View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLatham JLatham is offline
external usenet poster
 
Posts: 2,203
Default Loop until cell is empty

Try

Do ActiveCell < Empty AND ActiveCell < s2

"Ricky Pang" wrote:

Hi JLatham and other Experts,
I'm almost there. How do you improve this code so that the msgbox pops
up only when the activecell is not empty (which it does now) and only
when the activecell is not the s2 String? Presently, it asks to replace
the title when the activecell is already = s2.

Sub OtherOperatingExpense()
Dim s1 As String, s2 As String
s1 = "total operating expenses"
s2 = "Other Expense"

Cells.Find(What:=s1, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False,
SearchFormat:=False).Activate
ActiveCell.Offset(-2, 0).Range("A1").Select

Do While LCase(ActiveCell) = LCase(s2)
ActiveCell.Offset(-1, 0).Range("A1").Select
Loop

Do While ActiveCell < Empty
If MsgBox("[" & ActiveCell & "]" & " will be replaced with " & "[" &
s2 & "]", vbYesNo, _
"Updating Other Titles Changes") = vbYes Then
ActiveCell = s2
End If
ActiveCell.Offset(-1, 0).Range("A1").Select
Loop
End Sub

Thanks in advance,
Ricky


*** Sent via Developersdex http://www.developersdex.com ***