J
Johnny Meredith
I know this is a common question, and I have looked at past posts, but
I can't seem to make it work.
I have an Excel file developed from a text import. It has approx.
50,000 rows that represent 25,000 records (records are on two rows).
I'm trying to eventually get to Access, but using Excel to clean up
data. The final piece of code to write simply deletes every row where
cell A is empty.
I've tried two solutions. This is the first one:
For i = rng1.Rows(rng1.Rows.Count).Row To 1 Step -1
If IsEmpty(rng(i)) = True Then
rng(i).EntireRow.Delete
End If
Next
For some reason, the code is "interrupted" at the End If line, but it
does delete about 5,000 rows before it farts.
The second solution is:
Set rng = Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
Set rng = rng.SpecialCells(xlBlanks)
rng.EntireRow.Delete
I get the same error, but on line 3 of above (the cause is the special
cells selection is too large). Also, this piece of code does not
delete a single row before it quits. So I think this is not a
solution at all.
I've read some stuff that says to cycle through ranges backwards when
deleting rows to avoid these errors (which I've done in #1 above).
Also, that Excel gets "ahead of itself" and I need to tell the code to
"wait." (I don't have a clue what that means!) Your help is greatly
appreciated, either with improving the above code, or doing something
completely different. Also, I must do it programmtically.
Aside - anyone have any ideas on reading a fixed width text file line
by line and avoiding the whole manual import mess in the first place.
I'll warn you: these text files are terrible - no consistency.
I can't seem to make it work.
I have an Excel file developed from a text import. It has approx.
50,000 rows that represent 25,000 records (records are on two rows).
I'm trying to eventually get to Access, but using Excel to clean up
data. The final piece of code to write simply deletes every row where
cell A is empty.
I've tried two solutions. This is the first one:
For i = rng1.Rows(rng1.Rows.Count).Row To 1 Step -1
If IsEmpty(rng(i)) = True Then
rng(i).EntireRow.Delete
End If
Next
For some reason, the code is "interrupted" at the End If line, but it
does delete about 5,000 rows before it farts.
The second solution is:
Set rng = Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
Set rng = rng.SpecialCells(xlBlanks)
rng.EntireRow.Delete
I get the same error, but on line 3 of above (the cause is the special
cells selection is too large). Also, this piece of code does not
delete a single row before it quits. So I think this is not a
solution at all.
I've read some stuff that says to cycle through ranges backwards when
deleting rows to avoid these errors (which I've done in #1 above).
Also, that Excel gets "ahead of itself" and I need to tell the code to
"wait." (I don't have a clue what that means!) Your help is greatly
appreciated, either with improving the above code, or doing something
completely different. Also, I must do it programmtically.
Aside - anyone have any ideas on reading a fixed width text file line
by line and avoiding the whole manual import mess in the first place.
I'll warn you: these text files are terrible - no consistency.