ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   make autofill code conditional to avoid runtime error. (https://www.excelbanter.com/excel-programming/428308-make-autofill-code-conditional-avoid-runtime-error.html)

J.W. Aldridge

make autofill code conditional to avoid runtime error.
 
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


Don Guillett

make autofill code conditional to avoid runtime error.
 
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


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"J.W. Aldridge" wrote in message
...
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




All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com