ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Runtime Error (https://www.excelbanter.com/excel-programming/342227-runtime-error.html)

xgirl

Runtime Error
 
Hello, I realize this may not be the best code in the world but it works
till the end when I get a runtime error.

I have a column of a series of 1's and 0's - as in 20 consecutive 1's
followed by 100 consecutive 0's followed by 40 consecutive 1's etc. I want
the macro to locate the last 1 (or first 0) in the series and then run a
macro. My macro works until it gets to the last set of 0's and can't find a
1. Any help greatly appreciated!

Sub FillLowTotal()

Application.ScreenUpdating = False
Range("e5").Select
Do
Do Until ActiveCell = 0
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
ActiveCell.Select
ActiveSheet.Application.Run ("Lowtotal")
Range(Selection, Selection.End(xlDown)).Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues,
LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:=False).Activate
Loop Until IsEmpty(ActiveCell.Value)
End Sub

Jim Thomlinson[_4_]

Runtime Error
 
Your find is going to be an issue if it does not find anything to activate.
You might be able to get away with addin the line

On Error Resume Next

At the beginning of your code...
--
HTH...

Jim Thomlinson


"xgirl" wrote:

Hello, I realize this may not be the best code in the world but it works
till the end when I get a runtime error.

I have a column of a series of 1's and 0's - as in 20 consecutive 1's
followed by 100 consecutive 0's followed by 40 consecutive 1's etc. I want
the macro to locate the last 1 (or first 0) in the series and then run a
macro. My macro works until it gets to the last set of 0's and can't find a
1. Any help greatly appreciated!

Sub FillLowTotal()

Application.ScreenUpdating = False
Range("e5").Select
Do
Do Until ActiveCell = 0
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
ActiveCell.Select
ActiveSheet.Application.Run ("Lowtotal")
Range(Selection, Selection.End(xlDown)).Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues,
LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:=False).Activate
Loop Until IsEmpty(ActiveCell.Value)
End Sub


xgirl

Runtime Error
 
Thanks for the tip Jim. After playing around with that idea I was able to
get it to run using the following...

On Error GoTo Finished
Finished:
MsgBox "Complete"


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

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