VBA to clear contents of "" values within a range

L

Legacy 173085

Guest
I'm working on a number of macros to automate some reports I run at work and have hit another wall!
<style type="text/css">#avg_ls_inline_popup { padding: 0px; overflow: hidden; position: absolute; z-index: 9999; margin-left: 0px; margin-top: 0px; width: 240px; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px; }</style>
So far my macro creates a new sheet and copy/pastes data from the relevant pivot into the tool.

One of the columns is called 'Loaded" - the answer being either "Y" or ""

My problem is I've got a counta subtotal at the bottom and it's picking up the "" in its count - so it's just counting the total number not the total "Y"s which is what I need.

Does anyone know a way I can write it into my code to clear contents of the "" cells?

Any suggestions much appreciated!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
One way to do this is with the following code adapted as per what cells you want to delete and obviously where you want to repeat it. May be an easier way, I don't know.

Code:
Sub ClearCells()
Dim i As Integer

    For i = 1 To Selection.CurrentRegion.Rows.Count - 1
     If ActiveCell.Value = "" Then
        ActiveCell.ClearContents
     ActiveCell.Offset(1, 0).Select
     
     Else: ActiveCell.Offset(1, 0).Select
     End If
    Next i
End Sub
 
Upvote 0
Hi cb12, thanks for this!

Not sure why but this didn't pick up the blank cells - I guess the blanks from the pivot don't show as "" ??

But it doesn't matter i turned your code around so it skips the 'Y's and for else clears contents and that works perfect!

Thanks for your help :)
 
Upvote 0
cb12 - I tried this and it still doesn't work... It doesn't matter cos turning it around works fine, just interesting to know why not if you work it out!

thanks jonmo1 - i have autofilter on so i'm using subtotal counta - but thanks anyway

:)
 
Upvote 0
Perhaps have your formulas in the column 'Loaded' return 1 instead of "Y"
Then you can use count instead of counta in the subtotal
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
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