Code works with F8 but not when I just run it

zookeepertx

Well-known Member
Joined
May 27, 2011
Messages
576
Office Version
  1. 365
Platform
  1. Windows
I'm sure this ihas been answered before, but I can't find it; sorry.

I've got this macro that USED to work fine, but was unfinished. I haven't gotten back to finish it till just today and, when I started playing with it, it wouldn't work right. So, I've spent the day finding and fixing various little problems but still have one left. If I F8 through the code, everything works just fine but, if I just run it like normal, part of it just does not carry out its purpose in life, LOL! Here's the start of my code, including the trouble spot:

Code:
Sub Roster()
'Roster Macro-Jenny 7028014
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
End With
Worksheets.Add(After:=Worksheets(1)).Name = "BG"
Worksheets.Add(After:=Worksheets(1)).Name = "West"
Worksheets.Add(After:=Worksheets(1)).Name = "East"
lr = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
LR2 = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
lr3 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
'text-to-columns on raw data
Sheets(1).Range("A1:A" & lr).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
        :=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), _
        Array(7, 2)), TrailingMinusNumbers:=True
'Delete extra header rows throughout report
[B][COLOR=#FF0000]lr = Range("A" & Rows.Count).End(xlUp).Row
For i = lr To 8 Step -1
    If Range("A" & i).Value Like "P.*" Then
        Rows(i - 1 & ":" & i + 20).Delete
    End If
Next i[/COLOR][/B]

The original report is usually 7-9 pages long and, after the text-to-columns, each page's header section takes up 21 rows on the spreadsheet. I only want to keep the FIRST set of headers (in yellow below) because it's all going to be one spreadsheet and won't need any more headers ( in grey below).

I've got a very shortened form of the sheet to play with. If I just run the code, the deletion of those 21 rows simply doesn't happen, but if I F8 through it works fine. The really weird thing is, if I F8 through to the first set of "extra" headers and let it delete them, then let the macro continue on its own, it continues fine.

I'll post as short a version of my sheet here as I can:


6/30/2014Page1of9
P.O.Box5
LosAngeles,CA90051-5176
Phone()Fax()
B90-MonthlyRoster,EastCoast
PerformanceTeam
RosterofTrailerManifests
Manifest#
Load#
Created
Operator
Consolidator
Consignee
Trailer
LHCarrier
Loaded
Closed
Departed
Arrived
CtnsPcsLbsPU$Cons$LH$FSCTotal
Inv#
Spot
1272129JohnSmith
8199
58665/27/20144:56PM
5/28/2014 0:009:17:00PM
5/28/2014 0:0011:56:00PM
FLY
5/27/201458207999267.812,399.81439.87
cessuaJohnSmith-Direct
E0180202136.6735.39
6/30/2014Page2of9
P.O.Box5
LosAngeles,CA90051-5176
Phone()Fax()
B90-MonthlyRoster,EastCoast
PerformanceTeam
RosterofTrailerManifests
Manifest#
Load#
Created
Operator
Consolidator
Consignee
Trailer
LHCarrier
Loaded
Closed
Departed
Arrived
CtnsPcsLbsPU$Cons$LH$FSCTotal
Inv#
Spot
1277061JohnSmith
8265
408186/10/201410:40PM
6/10/2014 0:0011:28:00PM
6/10/2014 0:0011:52:00PM
CVEN
6/10/20142040233878.8701.4150.28
cessuaJohnSmith-PinnaclePoint
E01821765714.48
6/30/2014Page6of9
P.O.Box5
LosAngeles,CA90051-5176
Phone()Fax()
B90-MonthlyRoster,EastCoast
PerformanceTeam
RosterofTrailerManifests
Manifest#
Load#
Created
Operator
Consolidator
Consignee
Trailer
LHCarrier
Loaded
Closed
Departed
Arrived
CtnsPcsLbsPU$Cons$LH$FSCTotal
Inv#
Spot
1282592JohnSmith
8341
58686/25/201411:00AM
6/25/2014 0:008:14:00PM
6/25/2014 0:0011:36:00PM
SUP
6/27/20141201845.9455.25.94
ewewroJohnSmith-ECDC
E018469100

<colgroup><col style="width: 73pt; mso-width-source: userset; mso-width-alt: 4138;" width="97"> <col style="width: 57pt; mso-width-source: userset; mso-width-alt: 3242;" width="76"> <col style="width: 50pt; mso-width-source: userset; mso-width-alt: 2858;" width="67"> <col style="width: 64pt; mso-width-source: userset; mso-width-alt: 3626;" width="85"> <col style="width: 43pt; mso-width-source: userset; mso-width-alt: 2432;" width="57"> <col style="width: 50pt; mso-width-source: userset; mso-width-alt: 2816;" width="66"> <col style="width: 43pt; mso-width-source: userset; mso-width-alt: 2432;" width="57"> <col style="width: 38pt; mso-width-source: userset; mso-width-alt: 2176;" width="51"> <tbody>
</tbody>

Strange, huh? I don't see how it can F8 perfectly, but not work 10 seconds later just running it! :oops:

Thanks for your help!

Jenny
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

I expect it because you have not specified the sheet to use on the Range and Rows definitions.

When you step through you are on the right sheet.
 
Upvote 0
Hi,

I expect it because you have not specified the sheet to use on the Range and Rows definitions.

When you step through you are on the right sheet.

Hi Rick

No, because I always start out from sheet 1 no matter whether I'm trying to run it or F8 through. Actually, I usually take my original, untouched sheet and create a new workbook with only that sheet in it and start from there, letting the macro create the new sheets.
I'm afraid it's gotta be something else.

Thanks

Jenny
 
Upvote 0
I copied your data and code, made the changes I suggested, and it worked for me.

Before the changes, the final lr is set to the last row on the sheet named "East". So the macro only checks rows 1 to 8 for the P.
 
Upvote 0
I copied your data and code, made the changes I suggested, and it worked for me.

Before the changes, the final lr is set to the last row on the sheet named "East". So the macro only checks rows 1 to 8 for the P.

Oh, duhhhh, I see it now! Sometimes I read too fast and don't take in what I just saw! I won't get to try it until I get back into work on Monday, but it sure looks like it'll work right with your changes. I should know better than making that mistake. :rolleyes:
I'll be sure to let you know how it turns out after that.

Thanks for your help and your patience with me!

Jenny
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,673
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top