PC Review


Reply
Thread Tools Rate Thread

Copy Entire Row - Rick Rothstein ?

 
 
Hennie Neuhoff
Guest
Posts: n/a
 
      15th Aug 2009
You gave somebody this code, which works perfectly, however I
would like to delete te "closed" row instead of hiding it. Despite my
efforts I only manage to delete one row at a time. Obviously I’m
doing something wrong.
As always - thanks in advance.

Sub findtextcopyandhide()
With Worksheets("sheet15").Range("a1:a22")
Set c = .Find(What:="closed", After:=Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)

If Not c Is Nothing Then
firstAddress = c.Address
On Error Resume Next
Do
With Sheets("sheet6")
lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Rows(c.Row).Copy .Rows(lr)
Rows(c.Row).Hidden = True <----- Delete the row
End With
Set c = .FindNext(c)
Loop While Not c Is Nothing _
And c.Address <> firstAddress
End If
End With

--
HJN
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      15th Aug 2009
When deleting rows it's best to work from the bottom of the range up.

Untested...

Const SHEET_NAME as string = "sheet15"
Const RNG_SRCH as string = "A1:A22"
Const VAL_CLOSED as string="CLOSED"
dim x as long, rngSearch as range, c as Range

set rngSearch = Worksheets(SHEET_NAME).Range(RNG_SRCH)
for x = rngSearch.cells.count to 1 step-1
set c = rngSearch.Cells(x)
if ucase(c.value) = VAL_CLOSED then c.entirerow.delete
next x


Tim





"Hennie Neuhoff" <(E-Mail Removed)> wrote in message
news:19ED03BB-2397-4160-B0F0-(E-Mail Removed)...
> You gave somebody this code, which works perfectly, however I
> would like to delete te "closed" row instead of hiding it. Despite my
> efforts I only manage to delete one row at a time. Obviously I'm
> doing something wrong.
> As always - thanks in advance.
>
> Sub findtextcopyandhide()
> With Worksheets("sheet15").Range("a1:a22")
> Set c = .Find(What:="closed", After:=Cells(1, 1), _
> LookIn:=xlValues, LookAt:=xlWhole, _
> SearchOrder:=xlByRows, SearchDirection:=xlNext, _
> MatchCase:=False)
>
> If Not c Is Nothing Then
> firstAddress = c.Address
> On Error Resume Next
> Do
> With Sheets("sheet6")
> lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
> Rows(c.Row).Copy .Rows(lr)
> Rows(c.Row).Hidden = True <----- Delete the row
> End With
> Set c = .FindNext(c)
> Loop While Not c Is Nothing _
> And c.Address <> firstAddress
> End If
> End With
>
> --
> HJN



 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      15th Aug 2009
From the bottom up using small range

sub delrowswithcertaintext()
for i = 22 to 1 step -1
with sheets("sheet15")
if lcase(.cells(i,"a"))="closed" then .rows(i).delete
end with
next
end sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Hennie Neuhoff" <(E-Mail Removed)> wrote in message
news:19ED03BB-2397-4160-B0F0-(E-Mail Removed)...
> You gave somebody this code, which works perfectly, however I
> would like to delete te "closed" row instead of hiding it. Despite my
> efforts I only manage to delete one row at a time. Obviously I’m
> doing something wrong.
> As always - thanks in advance.
>
> Sub findtextcopyandhide()
> With Worksheets("sheet15").Range("a1:a22")
> Set c = .Find(What:="closed", After:=Cells(1, 1), _
> LookIn:=xlValues, LookAt:=xlWhole, _
> SearchOrder:=xlByRows, SearchDirection:=xlNext, _
> MatchCase:=False)
>
> If Not c Is Nothing Then
> firstAddress = c.Address
> On Error Resume Next
> Do
> With Sheets("sheet6")
> lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
> Rows(c.Row).Copy .Rows(lr)
> Rows(c.Row).Hidden = True <----- Delete the row
> End With
> Set c = .FindNext(c)
> Loop While Not c Is Nothing _
> And c.Address <> firstAddress
> End If
> End With
>
> --
> HJN


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Rick Rothstein Rick Rothstein Microsoft Excel Programming 1 27th Feb 2011 05:37 PM
Deleting - Rick Rothstein LiAD Microsoft Excel Programming 6 28th Aug 2009 09:22 AM
For Rick Rothstein retired bill Microsoft Excel Programming 1 7th May 2009 05:50 PM
Rick Rothstein Gordy99 Microsoft Excel Programming 0 28th Feb 2008 07:05 PM
Question for Rick Rothstein =?Utf-8?B?SmVubnkgQi4=?= Microsoft Excel Misc 0 27th Jun 2007 07:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 AM.