Slight adjustment to my macro [VBA]

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi team,

basically before runing my macro (see below) I want to check if there is any number in the range X4:X126.

If a number exists in the mentioned range, the macro will continue as is.

However, if there is no number in the mentioned range, I want to stop the macro and give the message "There is no number".

Thank you for your help. Much appreciated.

VBA Code:
Public Sub PRIO(ByRef control As Office.IRibbonControl)
Application.ScreenUpdating = False
Application.EnableEvents = False
With Range("X4:X126").SpecialCells(xlCellTypeBlanks)
If .EntireRow.Hidden = True Then
.EntireRow.Hidden = False
With Range("X3").Font
.Color = vbWhite: .Bold = False
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
Else
.EntireRow.Hidden = True
With Range("X3").Font
.Color = vbGreen: .Bold = True
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
End With
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Add this line near the top:
VBA Code:
    If Application.WorksheetFunction.Count(Range("X4:X126")) = 0 Then Exit Sub
 
Upvote 0
Solution
Do you need to specifically test for a number, or just any non-blank cells?
 
Upvote 0
Joe's already supplied the answer, so you should be good to go.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

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