Feb 08 2022 10:15 AM
Trying to set a Button with a macro that ultilizes "find and replace" But each time i use the button i want the value to find and replace to increase by one.
Have a worksheet i add daily numbers to in a row. I want to fill a different sheet with certain values from the rows end of the day then the next day after entering values i want to replace the previous days on the 2nd sheet.
Sub NightlySheet()
'
' NightlySheet Macro
' Fill Nightly sheet
'
'
Range("C3").Select
Cells.Replace What:="9", Replacement:="10", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
This is the macro I recorded. So basically, I want the next time I hit my button i want the macro to find "10" and replace with "11" and each time I hit the button to increase the values by 1
Feb 08 2022 11:18 AM
Create a sheet named Hidden.
Enter the last value that you used as "what" in cell A1 (9 in your example).
You can now hide the new sheet.
Change the macro as follows:
Sub NightlySheet()
'
' NightlySheet Macro
' Fill Nightly sheet
'
'
Dim v As Long
v = Worksheets("Hidden").Range("A1").Value + 1
Worksheets("Hidden").Range("A1").Value = v
Range("C3").Select
Cells.Replace What:=v, Replacement:=v + 1, LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
Feb 08 2022 11:47 AM
Feb 08 2022 11:59 AM
How about
Sub NightlySheet()
'
' NightlySheet Macro
' Fill Nightly sheet
'
'
Dim v As Long
v = Worksheets("Hidden").Range("A1").Value + 1
Worksheets("Hidden").Range("A1").Value = v
Range("C3").Select
Cells.Replace What:=CStr(v), Replacement:=CStr(v + 1), LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
Feb 08 2022 12:10 PM