IsEmpty Range vs. IsEmpty Cells

dandelion

New Member
Joined
Jul 16, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have a pivot table and a Column (AA) with Value next to the pivot table. I'm making a code that when I change the pivot table (e.g by selecting slicer): 1. If Range("AA11: AA5000") is not empty, a prompt message will ask whether want to clear the data in column AA? 2. But if Range("AA11: AA5000") is empty, no need to show the msgbox. However, when I write the code below, it does not work. I try to change Range to Cell("AA11") then it works. But I want range instead of Cells. Can you help me? TIA.

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

If IsEmpty(Range("AA11:AA50000")) = False Then
Dim answer As VbMsgBoxResult
answer = MsgBox("Do you want to clear the data?", vbYesNo, "Clear Data")
If answer = vbYes Then

Call ClearPreviousData
End If
End If

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
A multiple cell range returns an array. IsEmpty doesn't work on arrays.
You could either iterate through each cell in the range and use IsEmpty on each individual cell or maybe use this simpler alternative function:

Function IsRangeEmpty(ByVal R As Range) As Boolean IsRangeEmpty = (WorksheetFunction.CountA(R) = 0) End Function
 
Upvote 0
Solution
A multiple cell range returns an array. IsEmpty doesn't work on arrays.
You could either iterate through each cell in the range and use IsEmpty on each individual cell or maybe use this simpler alternative function:

Function IsRangeEmpty(ByVal R As Range) As Boolean IsRangeEmpty = (WorksheetFunction.CountA(R) = 0) End Function
It works well :) :) :) Thank you so much
 
Upvote 0
For future reference.

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: IsEmpty Range vs. IsEmpty Cells
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,757
Members
448,991
Latest member
Hanakoro

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