Please can someone assist with a macro to do the following:
1. Copy a row n number of times based on the data in column E. In the example attached, search for ";#". In this case, you need to copy row number 25 3 times.
You now should have 4 rows with exactly the same data.
2. Clean up the data in column E to have unique values with the rows just copied ie. in the example attached, one should end up with:-
"Bank account less than 6 months old" in row number 25
"Bank account not verified" in row number 26
"case not rerouted" in row number 27
"Case not spawned" in row number 28
Thanks
Neil
if you're not concerned about the rows being next to each other, this should workSub ParsePounds() Dim rSearch As Range Dim rFound As Range Dim vParse As Variant Dim vItem As Variant Const cItem = ";#" Set rSearch = Range(Cells(2, "E"), Cells(Rows.Count, "E").End(xlUp)) Set rFound = rSearch.Find(cItem, LookIn:=xlValues, LookAt:=xlPart) Do Until rFound Is Nothing vParse = Split(rFound.Text, cItem) For Each vItem In vParse If vItem = vParse(0) Then rFound = vItem Else Rows(Cells(Rows.Count, "A").End(xlUp).Offset(1).Row).Value = Rows(rFound.Row).Value Cells(Rows.Count, "E").End(xlUp) = vItem End If Next Set rFound = rSearch.FindNext(rFound) Loop Set rSearch = Nothing End Sub
Last edited by gjlindn; 09-02-2011 at 02:39 AM.
-GregIf this is helpful, pls click Star icon in lower left corner
If you do have data following the row(s) you're fixing and want to keep the new rows all together, this code would be betterSub ParsePounds() Dim rSearch As Range Dim rFound As Range Dim vParse As Variant Dim vItem As Variant Const cItem = ";#" Set rSearch = Range(Cells(2, "E"), Cells(Rows.Count, "E").End(xlUp)) Set rFound = rSearch.Find(cItem, LookIn:=xlValues, LookAt:=xlPart) Do Until rFound Is Nothing vParse = Split(rFound.Text, cItem) For Each vItem In vParse If vItem = vParse(0) Then rFound = vItem Else Rows(rFound.Row).Offset(1).Insert shift:=xlDown Rows(rFound.Row).Offset(1).Value = Rows(rFound.Row).Value Cells(rFound.Row, "E").Offset(1) = vItem End If Next Set rFound = rSearch.FindNext(rFound) Loop Set rSearch = Nothing End Sub
Last edited by gjlindn; 09-02-2011 at 02:39 AM.
-GregIf this is helpful, pls click Star icon in lower left corner
One more modification...This one keeps them in the same order they were originally listed in.Option Explicit Sub ParsePounds() Dim rSearch As Range Dim rFound As Range Dim vParse As Variant Dim vItem As Variant Dim iCount As Integer Dim bScrUpd As Boolean Dim bEvents As Boolean Dim lCalc As Long Const cItem = ";#" 'Improve performance With Application bScrUpd = .ScreenUpdating bEvents = .EnableEvents lCalc = .Calculation .ScreenUpdating = False .EnableEvents = False .Calculation = xlCalculationManual End With Set rSearch = Range(Cells(2, "E"), Cells(Rows.Count, "E").End(xlUp)) Set rFound = rSearch.Find(cItem, LookIn:=xlValues, LookAt:=xlPart) Do Until rFound Is Nothing iCount = 0 vParse = Split(rFound.Text, cItem) For Each vItem In vParse If vItem = vParse(0) Then rFound = vItem Else iCount = iCount + 1 Rows(rFound.Row).Offset(iCount).Insert shift:=xlDown Rows(rFound.Row).Offset(iCount).Value = Rows(rFound.Row).Value Cells(rFound.Row, "E").Offset(iCount) = vItem End If Next Set rFound = rSearch.FindNext(rFound) Loop Set rSearch = Nothing 'Restore Application Settings With Application .ScreenUpdating = bScrUpd .EnableEvents = bEvents .Calculation = lCalc End With End Sub
Last edited by gjlindn; 09-02-2011 at 02:54 AM. Reason: Added speed up script for larger files
-GregIf this is helpful, pls click Star icon in lower left corner
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks