LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Macro does not delete all the required rows

Hi

I start with a single worksheet in an excel file. My macro copies this
worksheet six times and renames each spreadsheet: Monday, Tuesday, Wednesday,
Thursday, Friday, Saturday, and Sunday.

Then macro then returns to the first spreadsheet and deletes all rows within
a range so that it only includes the data for Monday.

Then it moves to "Tuesday" and is supposed to delete all rows in a range
except Tuesday but it doesn't work properly. It deletes everything but
Tuesday and Wednesday.

This is the same for all spreadsheets until Sunday. "Sunday" retains only
Sunday data and is what I'm looking for.

How do I fix my macro?

My macro reads the following for "Tuesday" and "Wednesday". This should give
you an idea of what I'm doing. Thanks in advance for any help in this.

' TUESDAY
Sheets("Tuesday").Select
Row = 6

' KEEPS ROWS WITH TUESDAY AS THE DAY OF THE WEEK
Do While Cells(Row, 4).Value = "Monday"
Row = Row + 1
Loop
BeginningRow = 5
Lastrow = Row
RowRange = BeginningRow & ":" & (Lastrow - 1)
Rows(RowRange).Delete


Do Until Cells(Row, 4).Value < "Tuesday"
Row = Row + 1
Loop
BeginningRow = Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + 1
RowRange = BeginningRow & ":" & Lastrow
Rows(RowRange).Delete


Range("A1").Select
With Selection
.HorizontalAlignment = xlLeft
.Font.Size = 11
.Font.Bold = True
.Value = "The Average Minute Audience (AMA) for CBC Newsworld Programs"
End With
Range("A2").Select
With Selection
.HorizontalAlignment = xlLeft
.Font.Size = 9
.Font.Bold = True
.Value = WeekNumber & ":" & " " & DayofWeek & "," & " " & ReportMonth &
" " & ReportDay & "," & " " & ReportYear
End With

' PUTS A BORDER ON THE BOTTOM OF THE LAST ROW
Lastrow = ActiveSheet.UsedRange.Rows.Count
BorderRange = "A" & Lastrow & ":" & " " & "N" & Lastrow
Range(BorderRange).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Range("A1").Select

Selection.Cut Destination:=Range("C1")
Range("C2").Select
Selection.EntireRow.Insert
Columns("A:B").Select
Selection.Delete Shift:=xlToLeft
Range("A6").Select
Selection.EntireRow.Delete
Selection.EntireRow.Delete

' WEDNESDAY
Sheets("Wednesday").Select
Row = 6

' KEEPS ROWS WITH WEDNESDAY AS THE DAY OF THE WEEK
Do While Cells(Row, 4).Value = "Monday" Or Cells(Row, 4).Value = "Tuesday"
Row = Row + 1
Loop
BeginningRow = 5
Lastrow = Row
RowRange = BeginningRow & ":" & (Lastrow - 1)
Rows(RowRange).Delete



Do Until Cells(Row, 4).Value < "Wednesday"
Row = Row + 1
Loop
BeginningRow = Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + 1
RowRange = BeginningRow & ":" & Lastrow
Rows(RowRange).Delete


Range("A1").Select
With Selection
.HorizontalAlignment = xlLeft
.Font.Size = 11
.Font.Bold = True
.Value = "The Average Minute Audience (AMA) for CBC Newsworld Programs"
End With
Range("A2").Select
With Selection
.HorizontalAlignment = xlLeft
.Font.Size = 9
.Font.Bold = True
.Value = WeekNumber & ":" & " " & DayofWeek & "," & " " & ReportMonth &
" " & ReportDay & "," & " " & ReportYear
End With

' PUTS A BORDER ON THE BOTTOM OF THE LAST ROW
Lastrow = ActiveSheet.UsedRange.Rows.Count
BorderRange = "A" & Lastrow & ":" & " " & "N" & Lastrow
Range(BorderRange).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Range("A1").Select

 
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
Macro to delete rows wilko Excel Discussion (Misc queries) 3 July 23rd 09 08:13 PM
Macro does not delete all the required rows AG[_3_] Excel Programming 3 August 5th 08 01:54 PM
Using a Macro to delete all rows containing #N/A Shirley Munro[_4_] Excel Programming 4 September 6th 05 01:51 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM


All times are GMT +1. The time now is 10:44 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"