Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

View Data Using Form

0

Please Help! I have been trying for two days to get this

Set Rng = dataIDCol.Find(What:=searchValue, _

to work and I keep getting (Compile Error: Syntax error) Everything else works beautifully!!! If you could tell me how to fix this i would really appreciate it!

Answer
Discuss

Answers

0
Selected Answer

Hi MsBernie and welcome to the Forum. 

That line should end with a right bracket (and possibly something else) but without context/ a file it's very difficult to reply. The line ends 

Set Rng = dataIDCol.Find(What:=searchValue, _

REVISION: From your full code,  I see you have deleted or failed to copy the remainder of the line (and so the arguments needed by the .Find method). Please use the Select All below then Ctrl+C to copy this:

Set Rng = dataIdCol.Find(What:=searchValue, LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False)

 and use it to replace your line above. It should go from red (with error) to black in your revised code. Then run the macro.

Please note that the combination of " _" followed by Return can by used in VBA code to make it easier to read the arguments, so the tutorial may show (and you could use the code below instead of that above):

   Set Rng = dataIdCol.Find(What:=searchValue, _
         LookIn:=xlValues, _
         Lookat:=xlWhole, _
         SearchOrder:=xlByRows, _
         MatchCase:=False)

where the combination of a space+underscore at the end tells VBA to include whatever is in the next line of code. 

If that does NOT fix your problem, I supsect that your question relates to a paid course. If so, please don't post the whole code or file on the Forum. Instead you can ask the question directly to the course author Don by using the Contact link above (and sticking with the  Subject selection "Premium Course Questions").

If it does not relate to one, please edit your question to include the full macro (using the CODE button) or preferably attach a representative Excel file (with no personal data) and use the Add Files.. button to attach it.

Discuss

Discussion

Sub Select_Data()
'Search the data repository worksheet and return the found record interger
Dim sourceSheet As Worksheet
Dim dataSheet As Worksheet
Dim searchValue As Variant
Dim dataIdCol As Range
Dim recordRow As Integer
'Make some sheet variables so we can use those instead of hard-coding
Set sourceSheet = Sheets("Form")
Set dataSheet = Sheets("Data")
'Column that contains the value for which we will search.
Set dataIdCol = dataSheet.Range("A:A")
'Value to search for.
searchValue = InputBox("Input an Id.", "Record Search")
'Check if the user input a value and hit the OK button.
If searchValue <> vbNullString Then
    'Value input, so search for it.
      'Clear Data
   sourceSheet.Range("F4").Value = ""
   sourceSheet.Range("F6").Value = ""
    'Search
   Set Rng = dataIDCol.Find(What:=searchValue,)
       'Check if a record was found.
   If Not Rng Is Nothing Then
       ' Record Found!
              ' Get the row of the record.
       recordRow = Rng.Row
              ' Put the records information back into the form.
       sourceSheet.Range("F4").Value = dataSheet.Cells(recordRow, 1).Value
       sourceSheet.Range("F6").Value = dataSheet.Cells(recordRow, 2).Value
      Else
      ' Nothing found, tell the user.
      MsgBox "Record not found."
         End If
  End If
  End Sub  
       
      
MsBernie (rep: 2) Jan 20, '23 at 2:23 pm
This was a free Youtube video series; Idiot-proof forms in Excel. 
MsBernie (rep: 2) Jan 20, '23 at 2:26 pm
Thanks for selecting my Answer. I assume your problem is sorted now but if not , please say so (I would need to look tomorrow since I'm just on my mobile phone for now). 
John_Ru (rep: 6142) Jan 20, '23 at 3:52 pm
Good Morning John,
No, my issue has not been resolved. I posted the full code, (minus spaces because of exceeding character count). Any assistance would be appreciated!
MsBernie (rep: 2) Jan 23, '23 at 9:23 am
Good afternoon (here) Ms Bernie!

Please see my revised Answer- not sure which video you mean but I think they use this appraoch.

For future, please try to include sufficient info (and a file) in your question. Also, don't Select the Answer if it does NOT address your problem (otherwise we think we've fixed your issue). Do Select it when you have a working Answer (and don't keeping asking supplementary questions like "Can we also do this...?" as some people do!).
John_Ru (rep: 6142) Jan 23, '23 at 9:52 am
Yes!!! :-) Your select all sulution has fixed my issue!!! Thank you so very much! this is my first time writing, or I should say copying code and I did'nt know that all of that had to be included. I am Thrilled it is working and I can continue with the course! Everything has been so easy to follow I have since purchased this course and look foward to what is yet to come!!! Thank you and have an awesome day!!! :-)
MsBernie (rep: 2) Jan 26, '23 at 9:55 am
That's great MsBernie. Note that if you have questions on a purchased VBA course contents, please don't post them (or code/ files) here or elsewhere. Instead use the Contact link (in the green bar above) and use the Premium Courses option. Don will then answer you directly but allow him some time- he's a busy man!
John_Ru (rep: 6142) Jan 26, '23 at 10:58 am
Incidentally SelectAll isn't the name of a sub or macro, it's just a feature of code boxes here to make copying easier 
John_Ru (rep: 6142) Jan 26, '23 at 11:35 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login