VBA MSGBOX if column is blank

jfin1ty

New Member
Joined
May 15, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Hoping someone can help me with a problem I'm having with a sheet I have been working on.
I think it must be a super simple fix but i just can't seem to get it to work.

Basically I have the below report that generates as the result of some lengthy code.
Right before the macro finishes running, I need a VBA MSGBOX to appear and say "There are cells that are not blank in this range" if any cell in column R (other than R2) is not blank.
Everything I have tried so far to make this happen results in the msgbox always appearing regardless if the cells are empty or not.
I'm thinking that the cells in column R are showing as empty but may have some formatting applied to them that im not seeing so they aren't actually "blank".
It could also have to do with the fact the last row is way further down the sheet than it needs to be. Is there a way to reset the last used row to be the Grand total row?
If it helps, if any cells in column R are ever actually not blank, they will always be values and those values will always be greater than 0.

Book56.xlsx
ABCDEFGHIJKLMNOPQRST
1FromProductPriorityTonnes (t)CustomerDestination.....CoilsRCRC (PAL)PurlSlitsMini T/H'sNo Pack TypeZone
23ZONE 2
36ZONE 2
44ZONE 2
52ZONE 2
613ZONE 2
7
81114ZONE 3
9
10111ZONE 4
11
122ZONE 5
134ZONE 5
1417933ZONE 5
15
166ZONE 6
1762ZONE 6
1823ZONE 6
191ZONE 6
201ZONE 6
21
22111ZONE 2
231ZONE 2
243ZONE 2
256ZONE 2
2611ZONE 3
274ZONE 5
2818ZONE 5
291ZONE 5
302ZONE 6
31WPCIPA257.948GrandTotal631324766182Total
Daily Plan Final
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:T223Expression=SEARCH("Total",$F1)>0textNO
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try the following on your data. If the message box appears then you have something in that range, a space, a formula returning a blank, a non ASCII character - something other than conditional formatting (which shouldn't be causing the problem). The code assumes that the grand total row will always have something in column A.
VBA Code:
Sub Empty_R()
    Dim ws As Worksheet
    Set ws = Worksheets("Daily Plan Final")
    If WorksheetFunction.CountA(ws.Range("R3:R" & ws.Cells(Rows.Count, "A").End(xlUp).Row - 1)) > 0 _
    Then MsgBox "There are cells that are not blank in this range"
End Sub
 
Upvote 0
Solution
Try the following on your data. If the message box appears then you have something in that range, a space, a formula returning a blank, a non ASCII character - something other than conditional formatting (which shouldn't be causing the problem). The code assumes that the grand total row will always have something in column A.
VBA Code:
Sub Empty_R()
    Dim ws As Worksheet
    Set ws = Worksheets("Daily Plan Final")
    If WorksheetFunction.CountA(ws.Range("R3:R" & ws.Cells(Rows.Count, "A").End(xlUp).Row - 1)) > 0 _
    Then MsgBox "There are cells that are not blank in this range"
End Sub
Hi Kevin,
Interestingly enough, your code works for me.
When I run it and deliberately have values in column R, it tells me there are values there with the MSGbox.
When I run it and deliberately leave all values out of column R, I get no MSGbox.
Maybe it was the syntax of the code I was using beforehand to try and get the result I wanted but in any case I am able to use your code to achieve what i need.
Thanks.
 
Upvote 0
Hi Kevin,
Interestingly enough, your code works for me.
When I run it and deliberately have values in column R, it tells me there are values there with the MSGbox.
When I run it and deliberately leave all values out of column R, I get no MSGbox.
Maybe it was the syntax of the code I was using beforehand to try and get the result I wanted but in any case I am able to use your code to achieve what i need.
Thanks.
Happy to help & thanks for the feedback (y) :) As you say, it was probably a syntax thing (easily done).
 
Upvote 0

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

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