LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Copy rows from all sheets based on cell value

The previous code assumes that there will be a payment on each sheet. If that
is not the case then try this...

Option Explicit

Private Sub CopyPayments()
Dim rngFound As Range
Dim rngStart As Range
Dim rngPaste As Range
Dim wks As Worksheet

Set rngPaste = Sheet1.Range("A2")

For Each wks In Worksheets
If wks.Name < Sheet1.Name Then
Set rngFound = wks.Cells.Find("payment", , , xlWhole)
Set rngStart = rngFound
If Not rngFound Is Nothing Then
Do
rngFound.EntireRow.Copy rngPaste
Set rngFound = wks.Cells.FindNext(rngFound)
Set rngPaste = rngPaste.Offset(1, 0)
Loop Until rngStart.Address = rngFound.Address
Set rngStart = Nothing
End If
End If
Next wks
End Sub

HTH

"Jim Thomlinson" wrote:

Give this code a try...

Option Explicit

Private Sub CopyPayments()
Dim rngFound As Range
Dim rngStart As Range
Dim rngPaste As Range
Dim wks As Worksheet

Set rngPaste = Sheet1.Range("A2")

For Each wks In Worksheets
If wks.Name < Sheet1.Name Then
Set rngFound = wks.Cells.Find("payment", , , xlWhole)
Set rngStart = rngFound

Do
rngFound.EntireRow.Copy rngPaste
Set rngFound = wks.Cells.FindNext(rngFound)
Set rngPaste = rngPaste.Offset(1, 0)
Loop Until rngStart.Address = rngFound.Address
Set rngStart = Nothing
End If
Next wks
End Sub

HTH

"Steph" wrote:

Hi all. I have a workbook that has 100+ sheets in it. I added a sheet
(sheet1) , and in cell A1 of that sheet is the word "Payment".

I would like to cycle through every sheet, and copy every row that has the
word "payment" in column B into Sheet1, one after the other.

Anyone know how I can do this? Also, I would love to somehow tag each line
with the Sheetname it came from. Possible? Thanks!





 
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
copy rows to new sheet based on specific cell value dlballard Excel Worksheet Functions 5 April 24th 23 11:44 AM
Copy rows based on cell content billinr Excel Discussion (Misc queries) 2 February 14th 07 08:17 PM
Copy rows from one sheet to another based on a cell value SM1 Excel Worksheet Functions 1 December 21st 06 01:01 AM
Copy rows from one sheet to another based on a cell value SM1 New Users to Excel 1 December 21st 06 01:00 AM
Copy rows of one sheet into mutiple sheets based on column value Wesley Breshears Excel Discussion (Misc queries) 0 October 18th 06 03:19 PM


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