Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default How to find common strings of text then copy those rows elsewhere?

I have a spreadsheet with text data on over 500 lines (rows). I'm wanting to
find all those rows that have common text, ex.-"ABC Hospital", and move or
copy those rows to a different section or worksheet. Is there a way to do
this at one time rather than copy/pasting individual rows?
--
energyzone
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How to find common strings of text then copy those rows elsewhere?

Hi,

Your question is a bit thin on detail but this may help. Alt +f11 to open VB
editor, double click 'This workbook' and paste it in and run it.

It looks for your text string in the used range of column A and if it finds
copies the entirerow and pastes it into sheet 2

Sub copyit()
Dim MyRange, MyRange1 As Range
Sheets("Sheet1").Select 'Change to suit
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("A1:A" & lastrow)
For Each c In MyRange
If c.Value = "ABC Hospital" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
End If

Sheets("Sheet2").Select 'Change to where you want it
Range("A1").Select 'Change to where you want it
ActiveSheet.Paste
Application.CutCopyMode = False

End Sub

Mike

"energyzone" wrote:

I have a spreadsheet with text data on over 500 lines (rows). I'm wanting to
find all those rows that have common text, ex.-"ABC Hospital", and move or
copy those rows to a different section or worksheet. Is there a way to do
this at one time rather than copy/pasting individual rows?
--
energyzone

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default How to find common strings of text then copy those rows elsewh

Thanks! Unfortunately I know nothing about macros. When I click on This
Workbook, all my rows are displayed. Does it matter where I copy the material
you gave me?
--
energyzone


"Mike H" wrote:

Hi,

Your question is a bit thin on detail but this may help. Alt +f11 to open VB
editor, double click 'This workbook' and paste it in and run it.

It looks for your text string in the used range of column A and if it finds
copies the entirerow and pastes it into sheet 2

Sub copyit()
Dim MyRange, MyRange1 As Range
Sheets("Sheet1").Select 'Change to suit
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("A1:A" & lastrow)
For Each c In MyRange
If c.Value = "ABC Hospital" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
End If

Sheets("Sheet2").Select 'Change to where you want it
Range("A1").Select 'Change to where you want it
ActiveSheet.Paste
Application.CutCopyMode = False

End Sub

Mike

"energyzone" wrote:

I have a spreadsheet with text data on over 500 lines (rows). I'm wanting to
find all those rows that have common text, ex.-"ABC Hospital", and move or
copy those rows to a different section or worksheet. Is there a way to do
this at one time rather than copy/pasting individual rows?
--
energyzone

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How to find common strings of text then copy those rows elsewh

As I said in my original response,

ALT+F11 to open the VB editor. Double click 'this workbook' which is on the
left side and then paste the code in on the right hand side. Because you go
no detail in your original post you will have to change the name of the sheet
to search (Curently Sheet1) and the sheet to paste to (Currently sheet2)

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("A1:A" & lastrow)


In the 2 lines above you will need to change the A (£ instances) to the
actual column to search.

to run the code click
Tools|Macro|Macros.
Select the name of this macro (Copyit) and click run.

If your unesay with this then another respondent has given you a worksheet
based solution.

Mike

"energyzone" wrote:

Thanks! Unfortunately I know nothing about macros. When I click on This
Workbook, all my rows are displayed. Does it matter where I copy the material
you gave me?
--
energyzone


"Mike H" wrote:

Hi,

Your question is a bit thin on detail but this may help. Alt +f11 to open VB
editor, double click 'This workbook' and paste it in and run it.

It looks for your text string in the used range of column A and if it finds
copies the entirerow and pastes it into sheet 2

Sub copyit()
Dim MyRange, MyRange1 As Range
Sheets("Sheet1").Select 'Change to suit
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("A1:A" & lastrow)
For Each c In MyRange
If c.Value = "ABC Hospital" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Copy
End If

Sheets("Sheet2").Select 'Change to where you want it
Range("A1").Select 'Change to where you want it
ActiveSheet.Paste
Application.CutCopyMode = False

End Sub

Mike

"energyzone" wrote:

I have a spreadsheet with text data on over 500 lines (rows). I'm wanting to
find all those rows that have common text, ex.-"ABC Hospital", and move or
copy those rows to a different section or worksheet. Is there a way to do
this at one time rather than copy/pasting individual rows?
--
energyzone

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to find common strings of text then copy those rows elsewh

Alt + F11 to open the Visual Basic Editor.

CTRL + r to open the Project Explorer.

Select your workbook(project) and right-clickInsertModule.

Paste the code into that general module.

Do not paste it into the Thisworkbook module as Mike suggests. Thisworkbook
module should be reserved for event code, not general macros.

As an alternative.........have you looked at DataFilterAutofilter?


Gord Dibben MS Excel MVP


On Sun, 20 Apr 2008 08:14:00 -0700, energyzone
wrote:

Thanks! Unfortunately I know nothing about macros. When I click on This
Workbook, all my rows are displayed. Does it matter where I copy the material
you gave me?




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How to find common strings of text then copy those rows elsewh

Well spotted thanks for the correction

"Gord Dibben" wrote:

Alt + F11 to open the Visual Basic Editor.

CTRL + r to open the Project Explorer.

Select your workbook(project) and right-clickInsertModule.

Paste the code into that general module.

Do not paste it into the Thisworkbook module as Mike suggests. Thisworkbook
module should be reserved for event code, not general macros.

As an alternative.........have you looked at DataFilterAutofilter?


Gord Dibben MS Excel MVP


On Sun, 20 Apr 2008 08:14:00 -0700, energyzone
wrote:

Thanks! Unfortunately I know nothing about macros. When I click on This
Workbook, all my rows are displayed. Does it matter where I copy the material
you gave me?



  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,766
Default How to find common strings of text then copy those rows elsewhere?

Hi,

Another way to do it is the following:

1. Assuming your list starts from A2 downwards;
2. Enter the following formula in cell B2 and copy downwards
=IF(ISNUMBER(FIND("abc",A2)),MAX($B$1:B1)+1,""). Please replace the text in
quotes with the text you are looking for;
3. Now you will notice that wherever there is "abc" or your desired text in
the cell, it will have a number in column B'
4. Now in a seperate cell (say C2), just enter 1 and in the next cell down
below, do =C2+1 and copy downwads. You will now have all consecutive
natural numbers;
5. Use the INDEX() function in cell D2 and down below to get the desired
result.

Do let me know if you need any other help.

--
Regards,

Ashish Mathur
www.ashishmathur.com

"energyzone" wrote in message
...
I have a spreadsheet with text data on over 500 lines (rows). I'm wanting
to
find all those rows that have common text, ex.-"ABC Hospital", and move or
copy those rows to a different section or worksheet. Is there a way to do
this at one time rather than copy/pasting individual rows?
--
energyzone


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
common characters in seperate strings [email protected] Excel Discussion (Misc queries) 5 February 28th 07 06:50 PM
How to find and highlight common text in multiple columns ToExcelAtExcel Excel Discussion (Misc queries) 2 November 13th 06 10:44 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Excel find text and copy rows Denys-mark Excel Discussion (Misc queries) 2 July 25th 05 11:57 AM
Copy Rows found using Find All feature Scott H Excel Discussion (Misc queries) 3 May 2nd 05 06:04 PM


All times are GMT +1. The time now is 04:21 AM.

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"