Adjust macro to run from all sheets

Ron512

Board Regular
Joined
Nov 17, 2002
Messages
98
The below code copies a range from the “Staffing Plan” sheet to the “Resource HourCost” sheet.
It performs correctly when the “Staffing Plan” sheet is active but not when the “Resource HoursCost” sheet is active.
I have tried ActiveWorkbook as well as ThisWorkbook with the same result.

What changes are necessary to run the macro from the “Resource HourCost” or any sheet in the workbook?

As always thanks for your help.

Ron

Code:
Sub Staffing()
      
    Dim wb As Workbook
    Dim rCount As Long
    Dim LastColumn As Integer
    Dim wsd As Worksheet
    Dim wss As Worksheet
       
    On Error Resume Next
  
    Set wb = ThisWorkbook
    Set wsd = wb.Sheets("Resource HoursCost")
    Set wss = wb.Sheets("Staffing Plan")

    rCount = 34
        
    LastColumn = wss.UsedRange.Columns.Count

    wss.Range(Cells(4, 8), Cells(rCount, LastColumn)).Copy Destination:=wsd.Range("L4")

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
The last line should be
Code:
wss.Range(wss.Cells(4, 8), wss.Cells(rCount, LastColumn)).Copy Destination:=wsd.Range("L4")
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,995
Members
448,539
Latest member
alex78

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