Excel Macro to insert row based on data
Solved/Closed
Related:
- Excel macro to insert rows between data
- Transfer data from one excel worksheet to another automatically - Guide
- Insert gif in excel - Guide
- Spell number in excel without macro - Guide
- How to insert photo in word for resume - Guide
- Tmobile data check - Guide
2 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jan 19, 2012 at 03:50 AM
Jan 19, 2012 at 03:50 AM
many ways doing it. see whether the macro "test" helps
data is from A1 to C19
data is from A1 to C19
Sub undo() Range("D1:H1").EntireColumn.Delete Worksheets("sheet1").Cells.Clear Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("a1") Application.CutCopyMode = False End Sub
Sub test() Dim r As Range, vendor As Range, cvendor As Range Dim j As Long, cfind As Range, dest As Range, rdest As Range Application.ScreenUpdating = False undo Worksheets("sheet1").Activate Set r = Range(Range("A1"), Range("A1").End(xlDown)) r.AdvancedFilter xlFilterCopy, , Range("d1"), True Set vendor = Range(Range("D2"), Range("D2").End(xlDown)) For Each cvendor In vendor j = WorksheetFunction.CountIf(r, cvendor.Value) If j <> 12 Then Set cfind = r.Find(what:=cvendor.Value, lookat:=xlWhole) Set dest = Cells(Rows.Count, "F").End(xlUp).Offset(1, 0) Range(cfind, cfind.Offset(0, 1)).Copy Range(dest, dest.Offset(11, 0)) dest.Offset(0, 2) = 1 Set rdest = Range(dest.Offset(0, 2), dest.Offset(11, 2)) 'MsgBox rdest.Address rdest.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _ Step:=1, Stop:=12, Trend:=False Else Set dest = Cells(Rows.Count, "F").End(xlUp).Offset(1, 0) Range(cfind, cfind.Offset(11, 2)).Copy dest End If Next cvendor Range("D1").EntireColumn.Cells.Clear MsgBox "macro over" Application.ScreenUpdating = True End Sub
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jan 19, 2012 at 10:11 AM
Jan 19, 2012 at 10:11 AM
I am sending the file through speedyshare.com
download it from
http://speedy.sh/93pEW/ASA.xls
your main data is A1 to C19
copy this data that is A1:c19 to sheet2 also from A1 in that sheet
the result is column F to H
the macro is in vbeditor module
first run the macro in this file
if it is ok try in your file
find out whether there is confrontational difference between this file and your file
download it from
http://speedy.sh/93pEW/ASA.xls
your main data is A1 to C19
copy this data that is A1:c19 to sheet2 also from A1 in that sheet
the result is column F to H
the macro is in vbeditor module
first run the macro in this file
if it is ok try in your file
find out whether there is confrontational difference between this file and your file
Jan 19, 2012 at 09:37 AM
Jan 19, 2012 at 11:39 AM
Thank you so much for your time and effort.