First time working across sheets - Looking for some help and explanation

bsher

New Member
Joined
Jul 20, 2015
Messages
8
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:

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.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
maybe this
Code:
sh_WS.Cells(r_FS, 9).Interior.color = RGB(0, 0, 255)
must be
Code:
sh_[COLOR=#ff0000]WС[/COLOR].Cells(r_FS, 9).Interior.color = RGB(0, 0, 255)
since declared Dim sh_WC As Worksheet
 
Upvote 0
and also try to replace this line
Code:
sh_FS.Range(Cells(r_FS, 3), Cells(r_FS, 8)).Copy sh_WC.Range(Cells(r_WC, 32), Cells(r_WC, 37))
with this
Code:
Range(sh_FS.Cells(r_FS, 3), sh_FS.Cells(r_FS, 8)).Copy sh_WC.Cells(r_WC, 32)
 
Upvote 0
Thank you so much, both of your comments were very helpful and they helped my code run as intended! :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top