doesn't run macro if the adjacent cell doesn't contains numeric except zero or empty

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
146
Office Version
  1. 2019
Platform
  1. Windows
Hello

in last cell for column A contains TOTAL word and adjacent cell in column F contains formula to sum the values from row 20 .

so what I want if I click button is linked with my code and the last cell in column F for adjacent cell in TOTAL word contains zero or empty cell , then should pops message " you should fill numeric values in column F" and disable the code and if the last cell contains numeric values except zero , then should macro works when click button ( the button is not ACTIVE X).

with considering the numbers in column F and last cell for adjacent cell(TOTA) will be #,##0.00

thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try inserting this snippet at the beginning of your macro:
VBA Code:
Dim TotR As Long


TotR = Cells(Rows.Count, "A").End(xlUp).Row
If Cells(TotR, "F") = 0 Then
    MsgBox ("you should fill numeric values in column F. Macro is terminated")
    Exit Sub
End If
'
'your macro continues
'
'
 
Upvote 1
Solution
thank you .
the message show all of in the cases whether zero or not in lastrow for column F, any idea to fix it?
 
Upvote 0
I understood that the last cell in column A contains the word TOTAL, whereas on the same line column F shows a total; so my snippet find the last compiled cell in column A, look in col F of that line and check if it contains Zero o Non-zero
Does column A contains formulas below the row that shows TOTAL?

Anyway, try replacing the current Dim TotR As Long and line TotR = Cells(Rows.Count, "A").End(xlUp).Row with
VBA Code:
Dim TotR As Variant

TotR = Application.Match("TOTAL", Range("A1:A100000"), False)
Debug.Print "TotR=" & TotR
If it doesn't work, or a run-time error is shown, enter the Debug mode, then open the vba "Immediate window" (typing Contr-g should do the job; or Menu /View /Immediate window) anche check which value is shown for TotR: should be the line with Total; if Error 2042 double check that column A contains "TOTAL" without extra spaces
 
Upvote 0
I understood that the last cell in column A contains the word TOTAL, whereas on the same line column F shows a total;
yes that's correct
Does column A contains formulas below the row that shows TOTAL?
surely not.
unfortunately the same result.
 
Upvote 0
But you forget to examine and tell us the debug information in the vba "Immediate window"...
 
Upvote 0
sorry !
it gives F39 and this is what shows value .
 
Upvote 0
So debug info says TotR=39? Does A39 contains the word TOTAL?
And which is the content of F39 (of the same sheet)?
And what happens with your whole macro? It it executed till the end or the MsgBox ("you should fill numeric etc etc) is shown?
 
Upvote 0
And which is the content of F39 (of the same sheet)?
now I understood my bad ! , sorry !
I have to indicate sheet reference .
now your code works perfectly .(y)
thank you so much ;)
 
Upvote 0

Forum statistics

Threads
1,215,291
Messages
6,124,093
Members
449,142
Latest member
championbowler

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