Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
rem
 
Posts: n/a
Default select lines from multiple worksheets and write to new worksheet

I need to select certain lines from multiple worksheets (based on a field
value) and create a new worksheet containing all the lines. Any help would be
appreciated.

  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Rem,

Try the sub below. The assumptions a all your data sheets have the same layout, with headers in
row 1 and data starting in row 2, and the key value is always in the same column on each sheet.

HTH,
Bernie
MS Excel MVP

Sub ExtractDataFromMultipleSheets()

Dim myCell As Range
Dim mySht1 As Worksheet
Dim mySht2 As Worksheet
Dim myKey As Variant
Dim myKeyCell As Range
Dim myArea As Range
Dim myCol As Integer

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Extract").Delete
Application.DisplayAlerts = True
Set mySht1 = Worksheets.Add(Befo=Sheets(1))
mySht1.Name = "Extract"

Set myKeyCell = Application.InputBox( _
"Select a cell with the extract value", , , , , , , 8)
myKey = myKeyCell.Text
myCol = myKeyCell.Column


For Each mySht2 In ActiveWorkbook.Worksheets
If mySht2.Name < mySht1.Name Then
mySht2.Activate
Set myArea = mySht2.Cells(1, myCol).CurrentRegion

With myArea
.AutoFilter Field:=myCol - myArea.Column + 1, Criteria1:=myKey
.Offset(1, 0).Resize(myArea.Rows.Count - 1, .Columns.Count). _
SpecialCells(xlCellTypeVisible).Copy _
mySht1.Range("B65536").End(xlUp)(2)
mySht1.Range(mySht1.Range("A65536").End(xlUp)(2), _
mySht1.Range("B65536").End(xlUp)(1, 0)).Value = mySht2.Name
.AutoFilter
End With
End If
Next mySht2
mySht1.Columns.AutoFit
End Sub





"rem" wrote in message
...
I need to select certain lines from multiple worksheets (based on a field
value) and create a new worksheet containing all the lines. Any help would be
appreciated.



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
Formula checking multiple worksheets sonic-the-mouse Excel Worksheet Functions 2 June 5th 05 07:48 PM
split results to multiple worksheets Rich Excel Worksheet Functions 3 April 11th 05 07:51 PM
Select all worksheets J Shrimps, Jr. Excel Worksheet Functions 1 March 25th 05 10:27 AM
Consolidating entries from multiple worksheets Al Excel Worksheet Functions 1 February 22nd 05 12:14 AM
Easy way to sum multiple worksheets TNMAN Excel Worksheet Functions 4 December 7th 04 05:57 PM


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"