Copy Range with Blank formula still shows in COUNT

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
843
Office Version
  1. 365
Platform
  1. Windows
Hi

I'm copying Ranges using VBA or even manually and even if the result of a formula in the range is "" when pasted it shows up in the COUNT When I select the Column.

Only way to stop it showing in the Count is Filter the Column for Blanks, select them all and press delete

e.g.
Cell B2 is a, Cell B3 is b, Cell B4 is = =IF(B2="a","",B2)

When I highlight Column B the Count is 3 which is fine 2 values and a formula
However when I copy B2:B4 and Paste as Values in D2, when I highlight Colum D the count is still 3 even though Cell D4 shows as a blank when you select it. If I click on D4 and Press delete it shows as 2.

So when I copy Paste the Blank which is the result of a formula how can I paste so that it wont show up in a count when column is Selected

Code used in example above
VBA Code:
Range("B2:B4").Copy
Range("D2").PasteSpecial Paste:=xlPasteValues

Thanks
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You need to copy values like
VBA Code:
Range("D2:D4").Value = Range("B2:B4").Value
 
Upvote 0
Thanks but one of issues is, not sure how long initial range to copy is so could be D2:D50

Can't use current region as other values are next to it and I also format the range in separate line when copied e.g. .PasteSpecial Paste:=xlPasteFormats

Thought there was another way of it not appearing within the count when copy pasting blanks as a result of a formula
 
Upvote 0
You need to copy values, if you copy/paste as value, then you will get ""
 
Upvote 0
Try
VBA Code:
Sub test1()
Dim k&
k = WorksheetFunction.CountA(Range("B:B"))
Range("D2").Resize(k, 1).Value = Range("B2").Resize(k, 1).Value
End Sub
 
Upvote 0
Thanks but one of issues is, not sure how long initial range to copy is so could be D2:D50

Can't use current region as other values are next to it and I also format the range in separate line when copied e.g. .PasteSpecial Paste:=xlPasteFormats
I think there a couple of other question bundled into this.
See if this gives you any ideas:

VBA Code:
Sub CopyValues()

    Dim LastRow As Long
    
    ' Get Last Row of Copy Range
    LastRow = Range("B" & Rows.Count).End(xlUp).Row
    
    ' Copy Values Only and Convert "" to Blank (per Fluff)
    Range("D2:D" & LastRow).Value = Range("B2:B" & LastRow).Value
    
    ' Copy Format only
    Range("B2:B" & LastRow).Copy
    Range("D2:D" & LastRow).PasteSpecial Paste:=xlPasteFormats

End Sub
 
Upvote 0
Just another generic resize option for the value = value

VBA Code:
Sub CopyValue()
    With Range("B2:B" & Range("B" & Rows.count).End(xlUp).Row)
        Range("D2").Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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