Hello everyone! I am new to vba and have given myself a project to start learning. I am getting a run time error trying to use the match function. The code I have so far is:
Sub refresh()
Dim n As Double
Dim i As Integer, k As Integer, x As Integer
Dim wb1 As Workbook, wb2 As Workbook
Dim exercise As String
Set wb1 = Workbooks("training_goals.xlsm")
Set wb2 = Application.Workbooks.Open("C:\Users\Logan\Downloads\strength.csv", False, True)
n = wb2.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
'For k = 1 To 7
i = wb1.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
exercise = wb1.Sheets(1).Cells(2, 1).Text
x = Application.WorksheetFunction.Match(exercise, wb2.Worksheets(1).Range("a1:f5000"), 0)
'Next k
MsgBox (exercise)
'value = Application.WorksheetFunction.Match(Application.Workbooks(file1).Worksheets(7).Cells(2, 1), _
MsgBox (x)
End Sub
At the moment it does not make much sense as I have just started and am mostly troubleshooting. As you can see, there are two workbooks. Workbook 2 has data in a1:fn, where n is defined as above. I am trying to use the exercise criteria from workbook 1 to find data from workbook 2. Originally my code was
x = Application.WorksheetFunction.Match(exercise, wb2.Worksheets(1).Range("a1:f" & n), 0)
I have confirmed that the string assigned to exercise is also found in workbook 2. I have also confirmed that the rest of the code works. If you guys can point me in the right direction it would be much appreciated!
Sub refresh()
Dim n As Double
Dim i As Integer, k As Integer, x As Integer
Dim wb1 As Workbook, wb2 As Workbook
Dim exercise As String
Set wb1 = Workbooks("training_goals.xlsm")
Set wb2 = Application.Workbooks.Open("C:\Users\Logan\Downloads\strength.csv", False, True)
n = wb2.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
'For k = 1 To 7
i = wb1.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
exercise = wb1.Sheets(1).Cells(2, 1).Text
x = Application.WorksheetFunction.Match(exercise, wb2.Worksheets(1).Range("a1:f5000"), 0)
'Next k
MsgBox (exercise)
'value = Application.WorksheetFunction.Match(Application.Workbooks(file1).Worksheets(7).Cells(2, 1), _
MsgBox (x)
End Sub
At the moment it does not make much sense as I have just started and am mostly troubleshooting. As you can see, there are two workbooks. Workbook 2 has data in a1:fn, where n is defined as above. I am trying to use the exercise criteria from workbook 1 to find data from workbook 2. Originally my code was
x = Application.WorksheetFunction.Match(exercise, wb2.Worksheets(1).Range("a1:f" & n), 0)
I have confirmed that the string assigned to exercise is also found in workbook 2. I have also confirmed that the rest of the code works. If you guys can point me in the right direction it would be much appreciated!