Hi All,
This is my first time working across sheets. I tried to copy the format of another program that worked across sheets. This is my code:
The error I get here is Compile error: Next without For
So then I tried adding End Ifs to my code because maybe that was messing with it and this was my code after that
Then, the error that I got was Run-time error '1004': Method 'Range' of object '_Worksheet' failed
I'm not exactly sure what I'm doing wrong and what I'm doing right. Any help would be much appreciated.
This is my first time working across sheets. I tried to copy the format of another program that worked across sheets. This is my code:
Code:
Sub Search_Finder_Sheet()
Dim sh_WC As Worksheet
Dim sh_FS As Worksheet
Set sh_WC = ActiveWorkbook.Sheets("Walls_OR_Columns")
Set sh_FS = ActiveWorkbook.Sheets("Finder_Sheet")
Dim r_WC '--> r_WC goes from 2 to 225
Dim c_WC '--> c_WC goes from 30 to 37
Dim r_FS
Dim c_FS
For r_WC = 2 To 225
For r_FS = 2 To 250
If sh_WC.Cells(r_WC, 30) = sh_FS.Cells(r_FS, 1) Then
If sh_WC.Cells(r_WC, 31) = sh_FS.Cells(r_FS, 2) Then
sh_FS.Range(Cells(r_FS, 3), Cells(r_FS, 8)).Copy sh_WC.Range(Cells(r_WC, 32), Cells(r_WC, 37))
sh_WS.Cells(r_FS, 9).Interior.color = RGB(0, 0, 255)
Next r_FS
Next r_WC
End Sub
The error I get here is Compile error: Next without For
So then I tried adding End Ifs to my code because maybe that was messing with it and this was my code after that
Code:
Sub Search_Finder_Sheet()
Dim sh_WC As Worksheet
Dim sh_FS As Worksheet
Set sh_WC = ActiveWorkbook.Sheets("Walls_OR_Columns")
Set sh_FS = ActiveWorkbook.Sheets("Finder_Sheet")
Dim r_WC '--> r_WC goes from 2 to 225
Dim c_WC '--> c_WC goes from 30 to 37
Dim r_FS
Dim c_FS
For r_WC = 2 To 225
For r_FS = 2 To 250
If sh_WC.Cells(r_WC, 30) = sh_FS.Cells(r_FS, 1) Then
If sh_WC.Cells(r_WC, 31) = sh_FS.Cells(r_FS, 2) Then
sh_FS.Range(Cells(r_FS, 3), Cells(r_FS, 8)).Copy sh_WC.Range(Cells(r_WC, 32), Cells(r_WC, 37))
sh_WS.Cells(r_FS, 9).Interior.color = RGB(0, 0, 255)
End If
End If
Next r_FS
Next r_WC
End Sub
Then, the error that I got was Run-time error '1004': Method 'Range' of object '_Worksheet' failed
I'm not exactly sure what I'm doing wrong and what I'm doing right. Any help would be much appreciated.