PC Review


Reply
Thread Tools Rate Thread

Copy an entire row based on value in one cell

 
 
SueJB
Guest
Posts: n/a
 
      1st Feb 2008
APOLOGIES IF THIS IS A DUPLICATE POSTING - SYSTEM PROBLEMS!

Hello all

I hope you'll forgive me if this is answered somewhere in the archives, I've
looked right through but can't find anything and have time constraints.

I have working code that:
- cycles through a spreadsheet row by row
- if it finds a predetermined value anywhere in the row, it copies that
entire row to a new spreadsheet

the code is:

Sheets("Report data").Activate

firstRow = 1
lastRow = Range("A60000").End(xlUp).Row

For r = firstRow To lastRow

Set c = Rows(r).Find("Infrastructure") ****
If Not c Is Nothing Then
Rows(r).Copy
Sheets("Infrastructure").Activate
Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
Range("A65000").End(xlUp).Offset(0, 0).PasteSpecial (xlPasteFormats)
Sheets("Report data").Activate
End If
Next r

Sheets("Infrastructure").Activate
Range("a1").Select
Application.CutCopyMode = False
Application.StatusBar = False


I need to amend it so that it only copies the row if the required value is
in Column I of the row (so excluding any where it appears elsewhere, say in
colum A).

Can I do this by amending the line marked **** ? I've tried lots of
variations without success.

As ever, thanks in advance for any responses.

SJB
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      1st Feb 2008
Replace these two rows

Set c = Rows(r).Find("Infrastructure") ****
If Not c Is Nothing Then

with this

If Trim(Cells(r,"I")) = "Infrastructure" then


--

Regards,
Nigel
(E-Mail Removed)



"SueJB" <(E-Mail Removed)> wrote in message
news:2F2192D5-8CD3-419F-B02F-(E-Mail Removed)...
> APOLOGIES IF THIS IS A DUPLICATE POSTING - SYSTEM PROBLEMS!
>
> Hello all
>
> I hope you'll forgive me if this is answered somewhere in the archives,
> I've
> looked right through but can't find anything and have time constraints.
>
> I have working code that:
> - cycles through a spreadsheet row by row
> - if it finds a predetermined value anywhere in the row, it copies that
> entire row to a new spreadsheet
>
> the code is:
>
> Sheets("Report data").Activate
>
> firstRow = 1
> lastRow = Range("A60000").End(xlUp).Row
>
> For r = firstRow To lastRow
>
> Set c = Rows(r).Find("Infrastructure") ****
> If Not c Is Nothing Then
> Rows(r).Copy
> Sheets("Infrastructure").Activate
> Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
> Range("A65000").End(xlUp).Offset(0, 0).PasteSpecial
> (xlPasteFormats)
> Sheets("Report data").Activate
> End If
> Next r
>
> Sheets("Infrastructure").Activate
> Range("a1").Select
> Application.CutCopyMode = False
> Application.StatusBar = False
>
>
> I need to amend it so that it only copies the row if the required value is
> in Column I of the row (so excluding any where it appears elsewhere, say
> in
> colum A).
>
> Can I do this by amending the line marked **** ? I've tried lots of
> variations without success.
>
> As ever, thanks in advance for any responses.
>
> SJB


 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      1st Feb 2008
I just realized that you may be looking for the string within the cell? So
change the code from

If Trim(Cells(r,"I")) = "Infrastructure" then

to

If Instr(1,Cells(r,"I"),"Infrastructure", vbTextCompare) > 0 then



--

Regards,
Nigel
(E-Mail Removed)



"Nigel" <nigel-(E-Mail Removed)> wrote in message
news:C4AE862E-461A-48F6-8A0D-(E-Mail Removed)...
> Replace these two rows
>
> Set c = Rows(r).Find("Infrastructure") ****
> If Not c Is Nothing Then
>
> with this
>
> If Trim(Cells(r,"I")) = "Infrastructure" then
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "SueJB" <(E-Mail Removed)> wrote in message
> news:2F2192D5-8CD3-419F-B02F-(E-Mail Removed)...
>> APOLOGIES IF THIS IS A DUPLICATE POSTING - SYSTEM PROBLEMS!
>>
>> Hello all
>>
>> I hope you'll forgive me if this is answered somewhere in the archives,
>> I've
>> looked right through but can't find anything and have time constraints.
>>
>> I have working code that:
>> - cycles through a spreadsheet row by row
>> - if it finds a predetermined value anywhere in the row, it copies that
>> entire row to a new spreadsheet
>>
>> the code is:
>>
>> Sheets("Report data").Activate
>>
>> firstRow = 1
>> lastRow = Range("A60000").End(xlUp).Row
>>
>> For r = firstRow To lastRow
>>
>> Set c = Rows(r).Find("Infrastructure") ****
>> If Not c Is Nothing Then
>> Rows(r).Copy
>> Sheets("Infrastructure").Activate
>> Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial
>> (xlPasteValues)
>> Range("A65000").End(xlUp).Offset(0, 0).PasteSpecial
>> (xlPasteFormats)
>> Sheets("Report data").Activate
>> End If
>> Next r
>>
>> Sheets("Infrastructure").Activate
>> Range("a1").Select
>> Application.CutCopyMode = False
>> Application.StatusBar = False
>>
>>
>> I need to amend it so that it only copies the row if the required value
>> is
>> in Column I of the row (so excluding any where it appears elsewhere, say
>> in
>> colum A).
>>
>> Can I do this by amending the line marked **** ? I've tried lots of
>> variations without success.
>>
>> As ever, thanks in advance for any responses.
>>
>> SJB

>


 
Reply With Quote
 
SueJB
Guest
Posts: n/a
 
      3rd Feb 2008
Nigel

Fantastic, thank you, it worked like a charm and I am now "out from under"!

Sorry to take so long to respond, I really really appreciated your help.

Best wishes
Sue

"Nigel" wrote:

> I just realized that you may be looking for the string within the cell? So
> change the code from
>
> If Trim(Cells(r,"I")) = "Infrastructure" then
>
> to
>
> If Instr(1,Cells(r,"I"),"Infrastructure", vbTextCompare) > 0 then
>
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "Nigel" <nigel-(E-Mail Removed)> wrote in message
> news:C4AE862E-461A-48F6-8A0D-(E-Mail Removed)...
> > Replace these two rows
> >
> > Set c = Rows(r).Find("Infrastructure") ****
> > If Not c Is Nothing Then
> >
> > with this
> >
> > If Trim(Cells(r,"I")) = "Infrastructure" then
> >
> >
> > --
> >
> > Regards,
> > Nigel
> > (E-Mail Removed)
> >
> >
> >
> > "SueJB" <(E-Mail Removed)> wrote in message
> > news:2F2192D5-8CD3-419F-B02F-(E-Mail Removed)...
> >> APOLOGIES IF THIS IS A DUPLICATE POSTING - SYSTEM PROBLEMS!
> >>
> >> Hello all
> >>
> >> I hope you'll forgive me if this is answered somewhere in the archives,
> >> I've
> >> looked right through but can't find anything and have time constraints.
> >>
> >> I have working code that:
> >> - cycles through a spreadsheet row by row
> >> - if it finds a predetermined value anywhere in the row, it copies that
> >> entire row to a new spreadsheet
> >>
> >> the code is:
> >>
> >> Sheets("Report data").Activate
> >>
> >> firstRow = 1
> >> lastRow = Range("A60000").End(xlUp).Row
> >>
> >> For r = firstRow To lastRow
> >>
> >> Set c = Rows(r).Find("Infrastructure") ****
> >> If Not c Is Nothing Then
> >> Rows(r).Copy
> >> Sheets("Infrastructure").Activate
> >> Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial
> >> (xlPasteValues)
> >> Range("A65000").End(xlUp).Offset(0, 0).PasteSpecial
> >> (xlPasteFormats)
> >> Sheets("Report data").Activate
> >> End If
> >> Next r
> >>
> >> Sheets("Infrastructure").Activate
> >> Range("a1").Select
> >> Application.CutCopyMode = False
> >> Application.StatusBar = False
> >>
> >>
> >> I need to amend it so that it only copies the row if the required value
> >> is
> >> in Column I of the row (so excluding any where it appears elsewhere, say
> >> in
> >> colum A).
> >>
> >> Can I do this by amending the line marked **** ? I've tried lots of
> >> variations without success.
> >>
> >> As ever, thanks in advance for any responses.
> >>
> >> SJB

> >

>

 
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
Copy entire row(s) to another workbook based on partial cell crite Nik Microsoft Excel Programming 3 24th Sep 2009 07:04 PM
Copy Entire Row based on Cell Value Vincent A. Somoredjo Microsoft Excel Programming 4 13th Aug 2009 07:36 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Microsoft Excel Programming 4 5th Oct 2007 04:00 PM
Copy entire row to another sheet based on a criteria Brig Siton Microsoft Excel Misc 3 7th Aug 2006 09:04 PM
copy entire row based on a condition in a column cape Microsoft Excel Worksheet Functions 1 24th Mar 2004 09:51 PM


Features
 

Advertising
 

Newsgroups
 


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