KapardhiSarma
New Member
I never programed an excel macro, i'm facing a problem i hope excel macro can solve it, because i have huge amounts of data that need filtering its simple i will explain in an example
Original Table:
Column A Column B Column C Column D
name1 123456789
name2 234567783 3456677889
name3 213123123
name4 123451231 123412312 1231223523
what macro need to do is when he finds data in the third column or forth or both he insert a new row and put the fill it with the name from the column and the number from the third coloum so data will be like that
How table is supposed to be:
name1 123456789 (stays the same no data in colum3 or 4)
name2 234567783 (removes the third column data and put it in a new row)
name2 3456677889 (keeping the name that the data had)
name3 213123123 (stays the same no data in colum 3 or 4)
name4 123451231 (removes the third column data and forth colum data and put it in new rows)
name4 123412312
name4 1231223523
I am currently using the below code, but please help me how to get started from column B?
Original Table:
Column A Column B Column C Column D
name1 123456789
name2 234567783 3456677889
name3 213123123
name4 123451231 123412312 1231223523
what macro need to do is when he finds data in the third column or forth or both he insert a new row and put the fill it with the name from the column and the number from the third coloum so data will be like that
How table is supposed to be:
name1 123456789 (stays the same no data in colum3 or 4)
name2 234567783 (removes the third column data and put it in a new row)
name2 3456677889 (keeping the name that the data had)
name3 213123123 (stays the same no data in colum 3 or 4)
name4 123451231 (removes the third column data and forth colum data and put it in new rows)
name4 123412312
name4 1231223523
I am currently using the below code, but please help me how to get started from column B?
Code:
Sub test2()
Dim r As Range, x As Long, y As Long, Cnt As Long
Application.ScreenUpdating = False '**faster
With ActiveSheet 'specify actual sheet
Cnt = .Cells(.Rows.CountLarge, 1).End(xlUp).Row 'last non blank cell in column A
' rows loop
For y = Cnt To 1 Step -1 'start at last row and work up
Set r = .Range(.Cells(y, 1), .Cells(y, .Columns.Count).End(xlToLeft)) 'current row
' loop thru cells in current row
If Not IsEmpty(r(1)) Then '** skip empty cell
For x = r.Cells.Count To 3 Step -1
r.Offset(1).EntireRow.Insert Shift:=xlDown 'insert row
r(x).Cut r(2).Offset(1) 'number to column B
r(1).Offset(1).Value = r(1).Value 'name to column A
Next x
End If '**
Next y
End With
Application.ScreenUpdating = True '**
End Sub
Last edited by a moderator: