Changing months in Excel macro, reffering to another workbook

FMeister

New Member
Joined
Sep 26, 2016
Messages
2
Hello dear experts!

I have a whole bunch of workbooks with 30 sheets each, that I need to update each month. On top of each sheet, I'm using DATE-function: =DATE(2016;10;SHEETS()+14). That helps users telling which date the sheet is made for. Each month I am changing the month (in this case ;10;) to the new month. I want to automate this process and therefore I've created a new workbook where the number for the new month automatically is entered and should be implemented in the DATE-functions on alle workbooks and sheets.

Now I've just made this macro:

Code:
Sub New_date()
Dim Findtext As String
Dim Replacetext As String
With Sheets("14")
.Activate
Findtext = "=DATE(2016;10;SHEETS()+14)"
Replacetext = Workbooks("NEWMONTH.xlsm").Sheets("Sheet1").Range("C7").Value
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
With Sheets("14")
.Activate
DisplayAlerts = False
Findtext = "=DATO(2016;10;ARK()+14)"
Replacetext = Workbooks("NEWMONTH.xlsm").Sheets("Ark1").Range("C7").Value
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
End Sub

When I run it, nothing happens. I can't see what I am doing wrong? Can anybody help me?

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Error in displayed code. This is the macro code:

Code:
Sub New_date()
Dim Findtext As String
Dim Replacetext As String
With Sheets("14")
.Activate
Findtext = "=DATE(2016;10;SHEETS()+14)"
Replacetext = Workbooks("NEWMONTH.xlsm").Sheets("Sheet1").Range("C7").Value
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
With Sheets("14")
.Activate
DisplayAlerts = False
Findtext = "=DATE(2016;10;SHEETS()+14)"
Replacetext = Workbooks("NEWMONTH.xlsm").Sheets("Sheet1").Range("C7").Value
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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