MACRO message box error

SelinaR

Board Regular
Joined
Feb 2, 2012
Messages
65
Office Version
  1. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
Morning

I use the below Macro for an annual leave tracker.... if it sees 0 it gives a pop up message, however it seems to have an issue that it sometimes give an error when the minimum number is 5 or 3 and on other rows if it's 0 (correctly)

I have tried tweaking it but have had no success - any suggestions?


Sub ANL()
Dim range
Dim nResult As Long
range = ActiveCell.Row
If (Cells(range, 3) <= 0) Then
nResult = MsgBox( _
Prompt:="Leave Unavailable. Do you still want to continue?", _
Buttons:=vbYesNo)
If nResult = vbNo Then
Exit Sub
Else
Selection.FormulaR1C1 = "ANL"
Selection.Font.ColorIndex = 0
Selection.Font.Name = "Arial Rounded MT Bold"
End If
Else
Selection.FormulaR1C1 = "ANL"
Selection.Font.ColorIndex = 0
Selection.Font.Name = "Arial Rounded MT Bold"
End If
End Sub


THANKS
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
hi,
see if this change to your code helps:

Code:
Sub ANL()
    Dim Result As Long


    If Cells(ActiveCell.Row, 3).Value <= 0 Then
        Result = MsgBox("Leave Unavailable. Do you still want to continue?", 36, "Leave Unavailable")
        If Result = vbNo Then Exit Sub
    End If


    With ActiveCell
        .FormulaR1C1 = "ANL"
        .Font.ColorIndex = 0
        .Font.Name = "Arial Rounded MT Bold"
    End With


End Sub

Dave
 
Upvote 0
Hiya

that worked - thanks however - the spreadsheet has now been reformatted and coloumns removed...

how ill I know how to identify which cell the "if" formula is working off of to gain my YES/NO prompt:

currently shows:
If (Cells(range, 12) <= 0) Then...

Is 12 referring to a column? My data it needs to read to total prompt from is coloumn or is if from

or is it reading from Selection.FormulaR1C1 = "ANL"

thanks
 
Upvote 0
Yes, this is Column 12
Cells(range, 12)

This, should actually be..

Selection.Value = "ANL"
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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