![]() |
If then Cell comparison with text.
I am trying to run an If..Then sequence that will look at
the value (Text Value) in Cell A1 and A4 and if they are not equal insert a line on one side or the other. For Example the following: AB AB AB AB AB BC BC BC .... Would look like: AB AB AB AB AB BC BC BC .... So Far I have: If Worksheets(5).Cells(Count, 1).Value Worksheets (5).Cells(Count, 4).Value Then Worksheets(5).Range(Cells(Count, 1), Cells(Count, 2)).Insert Shift:=xlDown ElseIf Worksheets(5).Cells(Count, 1).Value < Worksheets (5).Cells(Count, 4).Value Then Worksheets(5).Range(Cells(Count, 4), Cells(Count, 5)).Insert Shift:=xlDown End If This does not work. It will keep inserting lines and never stagger the cells. Does anyone have any ideas? Thank you SS |
If then Cell comparison with text.
SS,
Try this Dim i As Long Range("A" & Cells(Rows.Count, "A").End(xlUp).Row + 1).Value = "ZZZZZZZZZ" Range("B" & Cells(Rows.Count, "B").End(xlUp).Row + 1).Value = "ZZZZZZZZZ" i = 1 Do If Cells(i, "A").Value Cells(i, "B").Value Then Cells(i, "A").Insert Shift:=xlDown ElseIf Cells(i, "A").Value < Cells(i, "B").Value Then Cells(i, "B").Insert Shift:=xlDown End If i = i + 1 Loop Until Cells(i, "A").Value = "ZZZZZZZZZ" And Cells(i, "B").Value = "ZZZZZZZZZ" Cells(i, "A").Value = "" Cells(i, "B").Value = "" -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "SS" wrote in message ... I am trying to run an If..Then sequence that will look at the value (Text Value) in Cell A1 and A4 and if they are not equal insert a line on one side or the other. For Example the following: AB AB AB AB AB BC BC BC ... Would look like: AB AB AB AB AB BC BC BC ... So Far I have: If Worksheets(5).Cells(Count, 1).Value Worksheets (5).Cells(Count, 4).Value Then Worksheets(5).Range(Cells(Count, 1), Cells(Count, 2)).Insert Shift:=xlDown ElseIf Worksheets(5).Cells(Count, 1).Value < Worksheets (5).Cells(Count, 4).Value Then Worksheets(5).Range(Cells(Count, 4), Cells(Count, 5)).Insert Shift:=xlDown End If This does not work. It will keep inserting lines and never stagger the cells. Does anyone have any ideas? Thank you SS |
All times are GMT +1. The time now is 05:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com