xlCellTypeBlanks, but no blank cells to delete

M

Melvin Purvis

As part of importing a csv file, I have to correct some errors in the data.
What I had before worked OK, but this weeks version of the csv made my code
bomb out.

What I'm doing is deleting some blank cells. This week, there were no blank
cells in the csv!

This is what I have now:

Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift=xlToLeft

What I need is something to do this:
Selection.SpecialCells(xlCellTypeBlanks).Select
If there are no blank cells, jump past the next line
Selection.Delete Shift=xlToLeft
to here

HELP PLEASE!
 
B

Barb Reinhardt

How about something like this

Dim myRange as range
Set myRange = Nothing
on error resume next
set myrange = Selection.SpecialCells(xlCellTypeBlanks)
on error goto 0
if not myrange is nothing then
myrange.Delete Shift=xlToLeft
end if
 
G

Gary''s Student

Count before Selecting:

If Selection.SpecialCells(xlCellTypeBlanks).Count>0 then
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift=xlToLeft
End If
 
G

Gord Dibben

Sub Shift_Blanks()
Dim c As Range
With Selection
Do
Set c = .Find("", LookIn:=xlValues, lookat:=xlWhole, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.Delete shift:=xlToLeft
Loop
End With

'do the rest of your stuff

End Sub


Gord Dibben MS Excel MVP
 
M

Melvin

Many thanks to all who posted with replies. All solutions accomplished the job,
showing there is more than one way to skin a cat. Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top