Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default find text and copy selected rows from text and loop

Hi

I'm need your expert help. In a worksheet I need to find the word
"Filename" in column B, then cut rows until the next "Filename" word. I need
this looping to start from the 2nd "Filename" word.

Upon highlighting rows I need to cut selected rows and add this to a new
worksheet. This needs to be done until all "Filename" words have been
searched.

I'm hoping this makes senses and that someone out there can help me.

Many thanks
Frederic
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default find text and copy selected rows from text and loop

Hi,

Put this in a 'General' module and run it. It assumes the source data are in
Sheet1 so change to suit

Sub Lime()
Dim LastRow As Long, count As Long, x As Long
Dim StartRow As Long, EndRow As Long
Dim MyRange As Range
Dim MySheet As String
MySheet = "Sheet1" ' Change as required
LastRow = Sheets(MySheet).Cells(Cells.Rows.count, "B").End(xlUp).Row
x = 1
Do
If Sheets(MySheet).Cells(x, 2) = "Filename" Then
count = count + 1
End If
x = x + 1
Loop Until count = 2
Set MyRange = Sheets(MySheet).Range("B" & x - 1 & ":B" & LastRow)
count = 0
For Each c In MyRange
If c.Value = "Filename" And count = 0 Then
StartRow = c.Row
count = count + 1
ElseIf c.Value = "Filename" And count 0 Then
EndRow = c.Row - 1
count = 1
Sheets(MySheet).Range("B" & StartRow & ":B" & EndRow).EntireRow.Copy
Worksheets.Add
ActiveSheet.Range("A1").PasteSpecial
StartRow = c.Row
End If
Next
End Sub


Mike

"bluewatermist" wrote:

Hi

I'm need your expert help. In a worksheet I need to find the word
"Filename" in column B, then cut rows until the next "Filename" word. I need
this looping to start from the 2nd "Filename" word.

Upon highlighting rows I need to cut selected rows and add this to a new
worksheet. This needs to be done until all "Filename" words have been
searched.

I'm hoping this makes senses and that someone out there can help me.

Many thanks
Frederic

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default find text and copy selected rows from text and loop


Hi Mike

I'm getting a run time error '9' subscrip of range for "LastRow"

LastRow = Sheets(MySheet).Cells(Cells.Rows.count, "B").End(xlUp).Row

Regards
Frederic

"Mike H" wrote:

Hi,

Put this in a 'General' module and run it. It assumes the source data are in
Sheet1 so change to suit

Sub Lime()
Dim LastRow As Long, count As Long, x As Long
Dim StartRow As Long, EndRow As Long
Dim MyRange As Range
Dim MySheet As String
MySheet = "Sheet1" ' Change as required
LastRow = Sheets(MySheet).Cells(Cells.Rows.count, "B").End(xlUp).Row
x = 1
Do
If Sheets(MySheet).Cells(x, 2) = "Filename" Then
count = count + 1
End If
x = x + 1
Loop Until count = 2
Set MyRange = Sheets(MySheet).Range("B" & x - 1 & ":B" & LastRow)
count = 0
For Each c In MyRange
If c.Value = "Filename" And count = 0 Then
StartRow = c.Row
count = count + 1
ElseIf c.Value = "Filename" And count 0 Then
EndRow = c.Row - 1
count = 1
Sheets(MySheet).Range("B" & StartRow & ":B" & EndRow).EntireRow.Copy
Worksheets.Add
ActiveSheet.Range("A1").PasteSpecial
StartRow = c.Row
End If
Next
End Sub


Mike

"bluewatermist" wrote:

Hi

I'm need your expert help. In a worksheet I need to find the word
"Filename" in column B, then cut rows until the next "Filename" word. I need
this looping to start from the 2nd "Filename" word.

Upon highlighting rows I need to cut selected rows and add this to a new
worksheet. This needs to be done until all "Filename" words have been
searched.

I'm hoping this makes senses and that someone out there can help me.

Many thanks
Frederic

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default find text and copy selected rows from text and loop


Hi Mike

I'm getting a run time error '9', subscript out of range on "LastRow"
LastRow = Sheets(MySheet).Cells(Cells.Rows.count, "B").End(xlUp).Row

Many thanks
Frederic



"Mike H" wrote:

Hi,

Put this in a 'General' module and run it. It assumes the source data are in
Sheet1 so change to suit

Sub Lime()
Dim LastRow As Long, count As Long, x As Long
Dim StartRow As Long, EndRow As Long
Dim MyRange As Range
Dim MySheet As String
MySheet = "Sheet1" ' Change as required
LastRow = Sheets(MySheet).Cells(Cells.Rows.count, "B").End(xlUp).Row
x = 1
Do
If Sheets(MySheet).Cells(x, 2) = "Filename" Then
count = count + 1
End If
x = x + 1
Loop Until count = 2
Set MyRange = Sheets(MySheet).Range("B" & x - 1 & ":B" & LastRow)
count = 0
For Each c In MyRange
If c.Value = "Filename" And count = 0 Then
StartRow = c.Row
count = count + 1
ElseIf c.Value = "Filename" And count 0 Then
EndRow = c.Row - 1
count = 1
Sheets(MySheet).Range("B" & StartRow & ":B" & EndRow).EntireRow.Copy
Worksheets.Add
ActiveSheet.Range("A1").PasteSpecial
StartRow = c.Row
End If
Next
End Sub


Mike

"bluewatermist" wrote:

Hi

I'm need your expert help. In a worksheet I need to find the word
"Filename" in column B, then cut rows until the next "Filename" word. I need
this looping to start from the 2nd "Filename" word.

Upon highlighting rows I need to cut selected rows and add this to a new
worksheet. This needs to be done until all "Filename" words have been
searched.

I'm hoping this makes senses and that someone out there can help me.

Many thanks
Frederic

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
How to find common strings of text then copy those rows elsewhere? energyzone Excel Worksheet Functions 6 April 20th 08 06:54 PM
Copy Selected Text from Text Box [email protected] Excel Programming 2 February 28th 07 11:58 AM
Excel find text and copy rows Denys-mark Excel Discussion (Misc queries) 2 July 25th 05 11:57 AM
open some txt files ,find text , copy the text before that to a single cell gus Excel Programming 2 July 11th 05 05:40 PM
Selecting text in cells & half of the Selected Text to be underLine Manish Singh Excel Programming 3 October 14th 04 07:34 PM


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