![]() |
Add cells if values are the same in multiple columns
Question from a newbie. Ok, this may sound simple but I have no idea what to do. I use this macro below that I got from this site. It searches column "A" for duplicates and adds other specific columns. What I need to find out is how to set it up to test for multiple duplicates (I will have 4 test values) (ie. If Columns A, D, E, F in row one are the same as in row two then add columns G,H,I,J and then delete row two
If anyone needs anymore information I will gladly provide it, as my working knowledge doesn't go much past "record a macro" or copy and paste one that I find here into a workbook. I have no idea if this is even possible, but it would help alot if someone can help me, as the file I need to do this to is about 8,000 rows long and will tak eme forever to do by hand Sub Main( Dim rng As Rang Dim rngFirst As Rang Dim c As Rang Dim lRow As Lon Dim cLastRow As Lon 'hard coded range :- cLastRow = Cells(Rows.Count, "A").End(xlUp).Ro Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp) For lRow = 1 To rng.Rows.Coun 'step thru all cells :- If Len(rng.Cells(lRow).Text) 0 The Set c = rng.Find(What:=rng.Cells(lRow) If Not c Is Nothing The Set rngFirst = D Set c = rng.FindNext(c If (Not c Is Nothing) And (c.Address < rngFirst.Address) The 'sum data (as if the 6th col. were a qty rngFirst.Offset(0, 2) = c.Offset(0, 2) + rngFirst.Offset(0, 2 rngFirst.Offset(0, 3) = c.Offset(0, 3) + rngFirst.Offset(0, 3 rngFirst.Offset(0, 4) = c.Offset(0, 4) + rngFirst.Offset(0, 4 rngFirst.Offset(0, 5) = c.Offset(0, 5) + rngFirst.Offset(0, 5 rngFirst.Offset(0, 6) = c.Offset(0, 6) + rngFirst.Offset(0, 6) 'or copy data. whatever '(this copies 3th thru 4th cell to right of c 'to 5th cell to right of rngFirst 'Range(c.Offset(0, 3), c.Offset(0, 4)).Copy ' rngFirst.Offset(0, 5 'remove this instance of the I c.Clea Els Exit D End I Loo End I End I Next lRo 'Remove all rows where we clear the I rng.Columns(1).SpecialCells(xlCellTypeBlanks).Enti reRow.Delet End Su Thank you very much for your time and consideration, as I am los Erin Myers |
Add cells if values are the same in multiple columns
You could turn calculation to manual, run the macro and put it back to what it
was. And since it's deleting a bunch of lines, make sure tools|Options|view tab|page breaks is unchecked. An alternative. add headers to each column select your range data|pivottable follow the wizard until you get to the step with a layout button on it. Hit that layout button. drag the button for A, D, E, F to the row range drag the button for G, H, I, J to the data range finish up the wizard Drag the "data" button to the cell directly to its right. Double click on each of the A, D, E, F headers and turn off the subtotals. If you like it and need the data as data (not as a pivot table), you can copy|paste special values and then use some of the techniques at Debra Dalgleish's site to fill the empty cells with the one above it: http://www.contextures.com/xlDataEntry02.html When I have to do this, sometimes I'll create a helper column and concatenate my columns (but separate by a unique character): =a2&"."&d2&"."&e2&"."&f2 then drag down. then use a pivot table to summarize by that column Convert to values and then do Data|text to columns to separate them again. Erin Myers wrote: Thanks, it seems to work great, it just takes a very long time. I went ahead and added to remove screen updating - but it doesn't seem to really speed it up much. Does anyone have an idea how to speed this code up at all - if not, I can use it, bu tit takes almost an hour to run Thanks for any other advice, and thankyou for your time thus far, Erin -- Dave Peterson |
All times are GMT +1. The time now is 05:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com