To take account of the uneven number of cells, this should work:
Before you start running the code, type "End" below the last row in column A, and leave column B blank, or the macro will not leave the loop. Either that or change the line:Code:Sub macro() Range("B3").Select Test3 = ActiveCell.Text Do While Test3 <> "" Test1 = ActiveCell.Offset(0, -1).Text Test2 = ActiveCell.Offset(-1, -1).Text Test3 = ActiveCell.Text If Test2 = "" Then ReturnCell = ActiveCell.Address ActiveCell.Offset(0, -1).Select Selection.End(xlUp).Select Test2 = ActiveCell.Text Range(ReturnCell).Select End If If Test1 = Test2 Then ActiveCell.Offset(0, -1).ClearContents ActiveCell.Offset(1, 0).Select Else ActiveCell.Offset(1, 0).Select End If Loop Range("A2").Select Test12 = ActiveCell.Offset(0, 1).Text Do While Test12 <> "" Test10 = ActiveCell.Text Test11 = ActiveCell.Offset(1, 0).Text Test12 = ActiveCell.Offset(0, 1).Text If Test10 <> "" And Test11 = "" And Test12 <> "" Then StartCell = ActiveCell.Address ActiveCell.Offset(1, 0).Select Do While ActiveCell.Text = "" ActiveCell.Offset(1, 0).Select Loop EndCell = ActiveCell.Offset(-1, 0).Address Range(StartCell & ":" & EndCell).Select With Selection .HorizontalAlignment = xlLeft .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .MergeCells = True End With Else End If ActiveCell.Offset(1, 0).Select Loop End Sub
to some sort of counter like:Code:Do While Test3 <> ""
Re shading:Code:Do While activecell.column < 100
Can you tell me what colours you want to use, and whether there is a coding criteria or whether you just want to use four colours randomly. If there is a criteria, what is it?
We're getting there I think.
![]()


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks