Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime error code 1004 Karen Excel Worksheet Functions 1 May 13th 10 12:21 AM
Runtime Error in code Lisa Excel Programming 2 June 2nd 08 10:51 PM
VB Code + Runtime error 91 [email protected] Excel Programming 0 February 13th 07 10:49 PM
RunTime Error 424 in a USERFORM's code JimP Excel Programming 0 November 26th 04 05:27 AM
Repost with code - Runtime error '1004' muziq2[_20_] Excel Programming 5 July 17th 04 12:46 AM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"