Macro Button to Reference Limit and Count

CpKGuelph

New Member
Joined
Mar 19, 2013
Messages
27
Hello All,
Wasn't able to find anything re my specific question so here goes:

I need a Macro button that will simply add '1' to a given cell, up to a maximum limit (contained in another cell)

EX:
Press Button -> Macro checks limit C107 -> macro adds '+1' to value contained in C108 (if under limit in C107)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Something like this should work:
VBA Code:
Sub Macro1()
    If Range("C108") < Range("C107") Then
        Range("C108") = Range("C108") + 1
    End If
End Sub
 
Upvote 0
Maybe:
VBA Code:
Private Sub CommandButton1_Click()
Range("C108").Value = Application.Min([C108] + 1, [C107])
End Sub
 
Upvote 0
Something like this should work:
VBA Code:
Sub Macro1()
    If Range("C108") < Range("C107") Then
        Range("C108") = Range("C108") + 1
    End If
End Sub
Thank you!! This worked perfectly, but my question was flawed it seems.

1653666449171.png

Follow up question:
Is there a way to also reference the date (Row 106) and have the macro populate a cell based on that? (1 button per week, but will only populate cell corresponding to current date)

EX:
B106 30-May
So macro would reference B106-F106 for date, and add +1 to current day, in addition to referencing 107 for quota (also based on current date)
 
Upvote 0
Incorporating JoeMo's clever formula into a loop that matches on day, try this:
VBA Code:
Sub AdditionMacro()

    Dim rng As Range
    Dim cell As Range
    
'   Look for date in B106:F106
    For Each cell In Range("B106:F106")
        If cell = Date Then
'           Add one, if necessary
            cell.Offset(2, 0).Value = Application.Min(cell.Offset(2, 0).Value + 1, cell.Offset(1, 0).Value)
'           Exit loop
            Exit For
        End If
    Next cell
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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