Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Need to sum row 7 columns based row 8 columns that are not Blank | Excel Worksheet Functions | |||
How do I copy columns between worksheets if the columns don't matc | Excel Worksheet Functions | |||
Macro simplifying - copy rows to worksheets based on values in 2 different columns | Excel Programming | |||
copy columns to other tabs based on searched value | Excel Programming | |||
Tallying columns based on values of 2 different columns | Excel Worksheet Functions |