I am running a simple code, however I get a type mismatch error.
The code is as follows
For i = 2 To rightcomp
matchC = Application.Match(Worksheets(2).Cells(1, i), Worksheets(3).Rows(1), 0)
MsgBox matchC
For jur = 2 To downlastcomp
matchr = Application.Match(Worksheets(2).Cells(jur, 1), Worksheets(3).Columns(temp), 0)
Worksheets(2).Cells(jur, i).Value = Worksheets(3).Cells(matchr, matchC).Value
Next jur
Next i
Initially I made a mistake in the following line:
matchr = Application.Match(Worksheets(2).Cells(jur, 1), Worksheets(3).Columns(temp), 0)
Intstead of
.Cells(jur, 1)
I had
.Cells(i, 1)
The code worked, however the values that were filled were incorrect. When I corrected the code, thus changed i to jur, the code fills in the first column correctly, however I get an error for the second column. Any ideas why?
Addition:
I have two sheets from different sources. I add a new sheet and reconcile the columns and rows. If the columns and rows are in both sheets I print them in the third sheet.
I then use the code above to fill in the rest of the data in the third sheet. Therefore it cannot be the case that the data is not found.
Also, with the below, the MsgBox is called correctly all the time, yet if I change the below to jur, the MsgBox is called only once and for the firs line.
.Cells(i, 1)
The values in matchC are strings and the values in matchR are numbers and strings.
Also, if comment out the below, the code does not induce Type Mismatch error.
Worksheets(2).Cells(jur, i).Value = Worksheets(3).Cells(matchR, matchC).Value