Macro to Increment a Cell Value by One

Puppies72

Board Regular
Joined
Mar 29, 2010
Messages
211
Hi all,

I need a macro (which I can assign to a button) to increment the values in a range of cells from AD4:AD204 by 1 but only if the cell is not empty.

Basically I am updating a sheet and some of the cells in that range will be empty until I add data so when I click on my "Update Sheet" button it will increment the values by one for cells with data in and then when I add new data and update those cells will begin their incrementation.

Hope that makes sense

thanks in advance!!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi You can try
Code:
Sub Macro5()
    On Error Resume Next
    Set C = Range("AD4:AD204").Cells.SpecialCells(xlCellTypeConstants)
    For Each cc In C
        cc.Value = cc.Value + 1
    Next
End Sub
 
Upvote 0
Fantastic! Works a charm...

Is there anyway to further modify that to update 10 sheets at once with a single click? :eek:
 
Upvote 0
I only want it to update certain sheets, those sheet names are reps:

Bart
Craig
Dan
Iain
Jason
Julian
Marc
Max
Neil
Pete
Ricky
Steve

many thanks
 
Upvote 0
perhaps;
Code:
[COLOR="Blue"]Public[/COLOR] [COLOR="Blue"]Sub[/COLOR] phoo1()
    [COLOR="Blue"]Dim[/COLOR] strRange [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] wks [COLOR="Blue"]As[/COLOR] Worksheet
    
    [COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] wks [COLOR="Blue"]In[/COLOR] ThisWorkbook.Worksheets
        strRange = wks.Range("AD4:AD204").Address(external:=[COLOR="Blue"]True[/COLOR])
        Range(strRange).Value = _
        Evaluate("IF(ROW(),IF(ISNUMBER(" & strRange & ")," & strRange & "+1,IF(" & strRange & "="""",""""," & strRange & ")))")
    [COLOR="Blue"]Next[/COLOR] wks
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
I only want it to update certain sheets, those sheet names are reps:

Bart
Craig
Dan
Iain
Jason
Julian
Marc
Max
Neil
Pete
Ricky
Steve

many thanks

Try;
Code:
[COLOR="Blue"]Public[/COLOR] [COLOR="Blue"]Sub[/COLOR] phoo1()
    [COLOR="Blue"]Dim[/COLOR] strRange [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] wks [COLOR="Blue"]As[/COLOR] Worksheet
    
    [COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] wks [COLOR="Blue"]In[/COLOR] Sheets([COLOR="Blue"]Array[/COLOR]("Bart", "Craig", "Dan", "Iain", "Jason", "Julian", "Marc", "Max", "Neil", "Pete", "Ricky", "Steve"))
        strRange = wks.Range("AD4:AD204").Address(external:=[COLOR="Blue"]True[/COLOR])
        Range(strRange).Value = _
        Evaluate("IF(ROW(),IF(ISNUMBER(" & strRange & ")," & strRange & "+1,IF(" & strRange & "="""",""""," & strRange & ")))")
    [COLOR="Blue"]Next[/COLOR] wks
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Hi,

I suggest you open a new sheet with called Sheet1
And put all the name under column A:A
Example A1 = Bart, A2 = Craig
So the code will be:

Code:
Sub Macro5()
    Set s = Sheets
    For Each ss In s
        Set c = Worksheets("Sheet1").Range("a:a").Find(ss.Name, LookIn:=xlValues, lookat:=xlWhole)
        If Not c Is Nothing Then
            On Error Resume Next
            Set c = Range("AD4:AD204").Cells.SpecialCells(xlCellTypeConstants)
            For Each cc In c
                cc.Value = cc.Value + 1
            Next
        End If
    Next
End Sub
 
Upvote 0
Hi guys,

Tried Jon's method and I'm getting an error saying that the macro is not available in current workbook or all macros may be disabled (which is not the case) though I may have done something wrong so don't assume it is your code!

have to head off to a meeting now but will try Alvin's method after lunch.

many thanks
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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