Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Deleting Rows

Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Deleting Rows

Here is one way, without a lot of re-write.

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
.Rows(Lrow - 1).Delete
Next Lrow




"mooresk257" wrote in message
...
Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row
with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Deleting Rows

Don't know what I was thinking. that will delete the wrong row, since you
have already deleted the row with the criteria string. So:

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
.Rows(Lrow).Delete
Next Lrow



"mooresk257" wrote in message
...
Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row
with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Deleting Rows

This also works:

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow & ":" & Lrow - 1).Delete
Next Lrow






"mooresk257" wrote in message
...
Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row
with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Deleting Rows

Hi

By before it do you mean the row above, if so

Rows(lrow & ":" & lrow - 1).Delete
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"mooresk257" wrote:

Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deleting Rows

I'd use:

'not sure what firstrow is here -- not sure if you want to
'use FirstRow or FirstRow - 1
'for example: if FirstRow is 1, then FirstRow - 1 won't work

'start with the row above
For Lrow = LastRow - 1 To FirstRow - 1 Step -1
'but look at the row below
If .Cells(Lrow + 1 , "A").Value = "Employee Name" Then
.Rows(Lrow).resize(2).Delete
end if
Next Lrow

ps. I hate that single line if/then/else (especially with the line continuation
character). My eyes sometimes miss it and I hate when that happes!

mooresk257 wrote:

Hi Folks,

I want to delete two rows - one row has the words "Employee Name" in the
first column, and the row before it. This for-next loop removes the row with
"Employee Name":

For Lrow = LastRow To FirstRow Step -1
If .Cells(Lrow, "A").Value = "Employee Name" Then _
.Rows(Lrow).Delete
Next Lrow

Any suggestions how to delete the row with "Employee Name" and the one
before it?

Thanks!

Scott


--

Dave Peterson
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
deleting blank rows for up to 60000 rows of data gbpg Excel Programming 4 December 27th 09 08:37 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Worksheet Functions 1 November 12th 08 01:39 PM
Help!!! I have problem deleting 2500 rows of filtered rows shirley_kee[_2_] Excel Programming 1 January 12th 06 03:15 AM


All times are GMT +1. The time now is 03:53 PM.

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

About Us

"It's about Microsoft Excel"