Dear Sirs,
I have researched the following macro, which starts ok, but stops when I try to set the data from 'mydata'. I suspect the use of Variant may be where my error lies. The search data is always 5 numerical characters.
The code I am trying to use is;
Sub Find_location()
ActiveSheet.Unprotect (no password set)
Dim Worksheet As Range
Dim mydata As Variant
mydata = InputBox("Enter the STD code to look for")
With Worksheets(1).Range("C1:C615").Select
Set mydata = .Find("mydata", LookIn:=xlWhole)
If found Then
MsgBox mydata("was found")
Else
MsgBox mydata("was not found")
End If
End With
ActiveSheet.Protect
End Sub
I realise I can find the data with Ctrl+F, but as I need this information frequently, I think a macro will help me a lot.
My ultimate goal is to find the data from my C column and print the corresponding D cell contents in the MsgBox. If the data is not found, the next MsgBox displays the 'not found' result. Therefore, searching for 01733 will produce Peterborough in the MsgBox.
Thank you for looking at this for me.
Hi John,
I did not realise the file I sent was in an encrypted folder. Obvious, with hindsight.
Thank you for your help. I have changed the macro name to a more descriptive name. There is only one macro. It works well at the start, but reports the number I enter is not found. I've tried to follow your code. It looks good to me, so I cannot work out where to go next.
Thank you once again for any advice you can offer.