Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default copy columns based on value in a particular row

Hi there,

Any idea how to write a macro that will:

- copy the columns (say rows 4 to 100) from each sheet within the active
workbook where the value in row 3 = value in cell A1 (there will be only one
column per sheet satisfying this condition - it should give an error if
there are more than 1)
- paste them one under another in column B of a newly created worksheet
(call it "summary")

Thank you very much in advance for your help on this...

Mark


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default copy columns based on value in a particular row

Untested, but something along the lines of this:

Sub abc()
Dim sh As Worksheet
Dim res As Variant
Dim rng As Range, rng1 As Range
Dim rng2 As Range, cnt As Long
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Summary").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = "Summary"
For Each sh In ThisWorkbook.Worksheets
If sh.Name < "Summary" Then
Set rng = sh.Range(sh.Cells(3, 1), sh.Cells(3, "IV").End(xlToLeft))
cnt = Application.CountIf(rng, sh.Range("A1"))
If cnt 1 Then
MsgBox sh.Name & " skipped due to bad data"
Else
res = Application.Match(sh.Range("A1"), rng, 0)
If IsError(res) Then
MsgBox sh.Name & " does not have matching column"
Else
Set rng1 = Worksheets("Summary").Cells(Rows.Count, 2) _
.End(xlUp)(2)
Set rng2 = sh.Range(sh.Cells(1, res), sh.Cells(Rows.Count, res) _
.End(xlUp))
rng2.Copy rng1
End If ' iserror(res)
End If ' cnt 1
End If ' sh.Name < "Summary"
Next sh
End Sub

--
Regards,
Tom Ogilvy

"markx" wrote:

Hi there,

Any idea how to write a macro that will:

- copy the columns (say rows 4 to 100) from each sheet within the active
workbook where the value in row 3 = value in cell A1 (there will be only one
column per sheet satisfying this condition - it should give an error if
there are more than 1)
- paste them one under another in column B of a newly created worksheet
(call it "summary")

Thank you very much in advance for your help on this...

Mark



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
Need to sum row 7 columns based row 8 columns that are not Blank Leew Excel Worksheet Functions 3 May 27th 08 04:21 PM
How do I copy columns between worksheets if the columns don't matc Miriam Excel Worksheet Functions 10 June 12th 06 04:29 PM
Macro simplifying - copy rows to worksheets based on values in 2 different columns markx Excel Programming 1 February 27th 06 03:36 PM
copy columns to other tabs based on searched value Marty[_6_] Excel Programming 0 February 8th 06 03:57 PM
Tallying columns based on values of 2 different columns Mctabish Excel Worksheet Functions 1 January 30th 05 10:40 AM


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