Run the macro even if the last 3 letters is renamed

deejay29

New Member
Joined
Feb 22, 2016
Messages
2
Good day,

May I ask if it is possible to run the macro even if some letters or characters on the title of the workbook I am working with is renamed?

this is the code I am working with:
Code:
Sub WBS()
    Dim sourceColumn As Range, targetColumn As Range

    Set sourceColumn = Workbooks("Total cost.xlsm").Worksheets(3).Range("A3:A300")
    Set targetColumn = Workbooks("backing sheet (Jan).xlsm").Worksheets(2).Range("D6:D300")

    sourceColumn.Copy
    targetColumn.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                          SkipBlanks:=False, Transpose:=False

    Application.CutCopyMode = False
    Call Resource_Name
End Sub

what I really want to do is run the macro even if the name of the workbook is changed. as you can see the value I am copying is pasted on "backing sheet (Jan).xlsm" I want to change the name to "backing sheet (Feb).xlsm" and I know it wont run because the target workbook does not exist technically.

is there any possible way to deal with this?

I tried to do this

Code:
Sub WBS()

    Dim monthAbbr As String
    monthAbbr = Range("monthAbbr").Value

    Dim sourceColumn As Range, targetColumn As Range

    Set sourceColumn = Workbooks("Total cost.xlsm").Worksheets(3).Range("A3:A300")
    Set targetColumn = Workbooks("backing sheet " & monthAbbr & ".xlsm").Worksheets(2).Range("D6:D300")

    sourceColumn.Copy
    targetColumn.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
                          SkipBlanks:=False, Transpose:=False

    Application.CutCopyMode = False
    Call Resource_Name
End Sub
but it gives me an error on
monthAbbr = Range("monthAbbr").Value
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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