Excell macro help

Copper Contributor

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

4 Replies

@KennyN87 

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
It is changing the value on the "Hidden" sheet but not changing the numbers on the sheet i want the macro to change

@KennyN87 

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
i looked again and i think your first one might be working i will play with it and see