Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to delete row based on criteria (first few characters of string)

Hi, Newbie here and looking for a macro code to delete the header off a
report. This report is multiple pages long and have imported into
Excel. Obviously every 60 rows or so, the report header shows up
again. I wish to delete the header and was hoping to build a macro to
do that. Wanted it to match the characters "RPS677" which is the first
6 characters of the string and then once it matches that, then delete
the next 7 rows (including the one with the RPS677 in it). Below is
an example of the report. I am putting R1-R12 to show the seperate
rows. Those numbers are not part of the original spreadsheet

R1 2051619 127 119 09:51 119 14:51 00025 00142
R2 DREAS DCAJT
R3 RPS677 BATCH STATUS OPERATOR REPORT
R4 SORTED BY BOX NUMBER AND BATCH NUMBER
R5 DEPOSIT JULIAN DATE: 121
R6 ------------------------------------------
R7 BOX BAT PREP DATA ENTERED
R8 NUMBER NBR JUL TIME JUL TIME COUNT KEY
R9 OPERATOR OPERATOR
R10 --------------------------------------------
R11 2051619 128 119 09:51 119 15:16 00025 00138
R12 DREAS DCAJT

I want to delete R3-R10 and was hoping to use the RPS677 as the
criteria to find that row, then delete the next 7. This would bring
the row with "2051619 128" up to R3. I can only match the first few
characters of the RPS677 string because at the end of that string it a
page number, which changes with each page.

Any help would be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Macro to delete row based on criteria (first few characters of string)

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim nCalculation

With Application
.ScreenUpdating = False
nCalculation = .Calculation
.Calculation = xlCalculationManual
End With

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Left(Cells(i, "A"), 6).Value = "RPS677" Then
Rows(i).Resize(7).Delete
End If
Next i

With Application
.Calculation = nCalculation
.ScreenUpdating = True
End With

End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

wrote in message
oups.com...
Hi, Newbie here and looking for a macro code to delete the header off a
report. This report is multiple pages long and have imported into
Excel. Obviously every 60 rows or so, the report header shows up
again. I wish to delete the header and was hoping to build a macro to
do that. Wanted it to match the characters "RPS677" which is the first
6 characters of the string and then once it matches that, then delete
the next 7 rows (including the one with the RPS677 in it). Below is
an example of the report. I am putting R1-R12 to show the seperate
rows. Those numbers are not part of the original spreadsheet

R1 2051619 127 119 09:51 119 14:51 00025 00142
R2 DREAS DCAJT
R3 RPS677 BATCH STATUS OPERATOR REPORT
R4 SORTED BY BOX NUMBER AND BATCH NUMBER
R5 DEPOSIT JULIAN DATE: 121
R6 ------------------------------------------
R7 BOX BAT PREP DATA ENTERED
R8 NUMBER NBR JUL TIME JUL TIME COUNT KEY
R9 OPERATOR OPERATOR
R10 --------------------------------------------
R11 2051619 128 119 09:51 119 15:16 00025 00138
R12 DREAS DCAJT

I want to delete R3-R10 and was hoping to use the RPS677 as the
criteria to find that row, then delete the next 7. This would bring
the row with "2051619 128" up to R3. I can only match the first few
characters of the RPS677 string because at the end of that string it a
page number, which changes with each page.

Any help would be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to delete row based on criteria (first few characters of string)

Thanks for the quick response. I am getting a run-time error '424' :
Object required. When I go to debug, it's stopping at the "If
Left(Cells(i, "A"), 6).Value = "RPS677" Then" part of the code.

Any words of advice?

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to delete row based on criteria (first few characters of string)

Thanks for the quick response. I am getting a run-time error '424' :
Object required. When I go to debug, it's stopping at the "If
Left(Cells(i, "A"), 6).Value = "RPS677" Then" part of the code.

Any words of advice?

Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Macro to delete row based on criteria (first few characters of string)

Syntax wrong

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim nCalculation

With Application
.ScreenUpdating = False
nCalculation = .Calculation
.Calculation = xlCalculationManual
End With

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Left(Cells(i, "A").Value, 6) = "RPS677" Then
Rows(i).Resize(7).Delete
End If
Next i

With Application
.Calculation = nCalculation
.ScreenUpdating = True
End With

End Sub


--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

wrote in message
oups.com...
Thanks for the quick response. I am getting a run-time error '424' :
Object required. When I go to debug, it's stopping at the "If
Left(Cells(i, "A"), 6).Value = "RPS677" Then" part of the code.

Any words of advice?

Thanks in advance





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to delete row based on criteria (first few characters of string)

Works like a charm. I appreciate your help!

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
Delete rows based on certain criteria Coal Miner Excel Discussion (Misc queries) 2 March 3rd 06 05:56 PM
use macro to insert characters at the beginning of a string dcmackie Excel Programming 4 April 4th 05 12:35 AM
Column Delete based on String scott Excel Programming 19 February 22nd 05 06:53 PM
Delete characters from a string Ron[_18_] Excel Programming 7 February 19th 04 04:24 PM
Cut and Paste macro based on criteria then delete empty rows samst Excel Programming 4 November 2nd 03 09:33 PM


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