PDA

View Full Version : Replace a text with a future data



EdwardOcampo
09-06-2017, 06:19 AM
HI!
Trying to replace this:

"Current + 4 Shortages" with "January Shortages"

Code: Cells.Replace what:="Cur+4 Shortage", Replacement:=MonthName(4 + Month(Now())) & " Shortage

The syntax was working last month, but It's not working on this month. Weird..

offthelip
09-06-2017, 07:08 AM
it is because 9+4 =13 which isn't a month number, while 8+4 =12 which is december

gmaxey
09-06-2017, 07:12 AM
I don't see how "Current + 4" could ever be found using search for "Cur+4"


Cells.Replace What:="Current + 4 Shortages", Replacement:= _
MonthName(Month(DateAdd("M", 4, Now))) & " Shortages"

Kenneth Hobs
09-06-2017, 07:15 AM
Sub Main()
If 4 + Month(Date) > 12 Then
Cells.Replace what:="Current + 4 Shortage", Replacement:=MonthName((4 + Month(Date) - 12)) & " Shortage"
Else
Cells.Replace what:="Current + 4 Shortage", Replacement:=MonthName(4 + Month(Date)) & " Shortage"
End If
End Sub

EdwardOcampo
09-06-2017, 07:22 AM
Hi Greg,

It was typo on my end.

By the way, it worked... Thank you so much.

Enjoy your day.

gmaxey
09-06-2017, 07:32 AM
You're welcome. I didn't even pick up the "13" issue because I just don't ever code that way.

snb
09-06-2017, 07:40 AM
Sub M_snb()
Cells.Replace "Current + 4", MonthName((Month(Date) + 3) Mod 12 + 1)
End Sub