VBA thinks blank rows aren't blank?

bozack

New Member
Joined
Apr 9, 2002
Messages
9
Hello,

I have small VBA macro that copies a few lines of some variable data and then goes to another spreadsheet, finds the last row of data and then pastes the values into the next row. Since my original dat can be 1-10 rows of data with formulas in each cell, sometimes there's up to 10 rows of data and other times there's only one row of data. The rows without data have formulas such as =If(A2="","",A2) and I am copying this and then special pasting the values into the 2nd sheet. The problem is, even though I'm pasting rows with blank cells, when I later go back and look for the last row of data, it thinks there's data in the blank cells where I just pasted "" or nothing into them. How can i prevent these blank rows from looking like they contain data?


This is the line of code I'm using to find the last blank row:

NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Those cells aren't actually "blank". They contain a null character.

One idea would be to find what Excel says is the "last row", then loop backwards to find the last row that does not contain a null character:

Code:
Dim NextRow as Long, i as Long
NextRow = Range("A" & Rows.Count).End(xlUp).Row
For i = NextRow to 1 Step -1
    If Range("A" & i).Value <> "" Then 
        NextRow = i + 1
        Exit For
    End If
Next i
 
Upvote 0
The problem is that
"" is NOT a Blank. It is a Null Text String.
It technically IS a Value.
Even after paste special / Values.

You can convert those Null Strings to Blanks with something like

Range("A:A").Value = Range("A:A").Value

Hope that helps.
 
Upvote 0
Thanks All!! I've sorted it. Yes, they are null characters as opposed to blank. My work around is to filter the cells before copying and filter a specific column that is supposed to have something in it, this eliminates the rows with the null characters. Thanks!!
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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