Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub Tidy()
Dim cLastRow As Long Dim rng As Range Dim i As Long 'work out the last row that in column B that contains data 'bys starting at the bottom (Rows.Count), and working 'up (.End(xlUp)) cLastRow = Cells(Rows.Count, "B").End(xlUp).Row 'loop backwards from our newly determined last row to 'row 2 (only need row 2 as we are comparing to previous 'and row 1 doesn't have a previous) For i = cLastRow To 2 Step -1 'first test if column A in the current row is blank, as this 'identifies the data that we want to append to previouys 'row If Cells(i, "A").Value = "" Then 'then append the data for column B in this row to the 'data in column B for the previous row, separating with ' a space Cells(i - 1, "B").Value = Cells(i - 1, "B").Value & _ " " & Cells(i, "B").Value 'we won't delete these rows yet, but just save the 'matched cells in a range object. We have to cater 'for the fact that first time, the range object is empty 'so we can't union it, but subsequent times we can If rng Is Nothing Then Set rng = Cells(i, "A") Else Set rng = Union(rng, Cells(i, "A")) End If End If 'and onto the next one Next i 'all processed, so first check that we have found some If Not rng Is Nothing Then 'if so delete the entirerows of those cells that we found 'and saved in the range object rng.EntireRow.Delete End If End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "MtK" wrote in message om... Thanks Bob. worked perfectly, if you can, can you add a few comments as im trying to learn how to do this stuff and understand what is going on in your macro exactly. thanks again. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
sumproduct function / VB user defined function | Excel Discussion (Misc queries) | |||
i can not find user definded on the function category | Excel Discussion (Misc queries) | |||
Function, User Defined | Excel Programming | |||
Help with user function please | Excel Programming | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |