If... then... Else statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Morning all

I have three sheets that I am trying to format. The formatting follows a
search by description and then formats that row.

In the first sheet, I have to change one description and then carry on the
formatting. But in the next two sheets that description doesn't appear.

I'm pretty inexperienced to Macros, so how would I "ask" the following
question of it?

If I find "tax-benefits in kind" change the description to "tax in kind" and
then carry on to find "salaries" and "expenses" and format them as usual
But If I can't find "tax-benefits in kind" just carry on and format
"salaries" & "expenses" as usual.

At the moment I have the following:

If Cells.Find(What:="TAX-BENEFITS IN KIND", After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext _
, MatchCase:=False).Activate = False Then
Range("A1").Select

ElseIf Cells.Find(What:="TAX-BENEFITS IN KIND", After:=ActiveCell,
LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext _
, MatchCase:=False).Activate = True Then
ActiveCell.Value = "TAX-BENFITS IN KIND"
Range("A1").Select

End If

Cells.Find(What:="SALARIES", After:=ActiveCell, LookIn _
:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False).Activate
Selection.End(xlToLeft).Select

thisrow = Selection.Row

With Range(Cells(thisrow, 1), Cells(thisrow, 11)).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Range(Cells(thisrow, 1), Cells(thisrow, 11)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

So in a nutshell, I want it to find "Tax-Benefits in kind" and change to
"Tax in Kind" and then format "salaries" but if "Tax-Benefits in kind"
doesn't appear then ignore the change of name and just go on to format
salaries.

Any help would be appreciated.

Thanks!!!

Mike
 
Dim cell As Range

Set cell = Nothing
Set cell = Cells.Find(What:="TAX-BENEFITS IN KIND", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not cell Is Nothing Then
cell.Value = "TAX IN KIND"
End If

Set cell = Nothing
Set cell = Cells.Find(What:="SALARIES", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not cell Is Nothing Then
With Range(Cells(cell.Row, 1), Cells(cell.Row,
11)).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Range(Cells(cell.Row, 1), Cells(cell.Row,
11)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If

Set cell = Nothing


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Back
Top