if not empty cells skip

M

Miree

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."
 
P

Patrick Molloy

if you're selecting the row AFTER the last used row, then surely its blank
anyways??
whats the point of the code?
 
M

Mike H

Hi,

One way would be to simply trap the error and move on. Note also I've
combined you statement into a single line and got rid of all the select bits

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
On Error GoTo getmeout
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow +
1).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = ".."
getmeout:


Mike
 
M

Mike H

The row being selected is the one after the last used cell in column A which
could have data in
 
P

Patrick Molloy

or, to avoid using GOTOs and setting error traps....

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

Set blanks = Range("B" & lngLastRow + 1 & ":DY" & lngLastRow +
1).Find(xlCellTypeBlanks)
If Not blanks Is Nothing Then
blanks.FormulaR1C1 = ".."
End If
 

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