make autofill code conditional to avoid runtime error.

J

J.W. Aldridge

In this portion of my code, I get an runtime error IF e2 is blank. I
need this to be conditional.
Therefore, if e2 is blank, avoid the autofill and keep going to next
step in code... Do not give me the runtime error.


With ThisWorkbook.Worksheets("2mindex")
Set rngData = .Range("e2:e" & .Cells(.Rows.Count, "e").End
(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row,
rngFormula.Column))
End With
 
D

Don Guillett

test this.modify to suit

Sub dontdoifblank()
With ThisWorkbook.Worksheets("sheet4")
If Not Len(Application.Trim(.Range("e2"))) < 1 Then
Set rngData = .Range("e2:e" & .Cells(.Rows.Count,
"e").End(xlUp).Row)
Set rngFormula = .Range("f2")
rngFormula.AutoFill _
Destination:=.Range(rngFormula, _
.Cells(rngData.Rows(rngData.Rows.Count).Row, rngFormula.Column))
End If
End With

End Sub
 

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