Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting rows based on the contents of the column 1

Status
Not open for further replies.

dyana

Technical User
Mar 26, 2002
27
US
If I have a range from d5:z5, and column "D" has various text references and numbers.

I want to format the rows, in column "D", that have the word "Price" as currency, and format the rest as comma without decimal places.

Does anybody know how to do this.

dyana
 
Hi dyana

You might want to try the below code:


Sub formatRange()

Dim myRow As Integer, myCol As Integer
Dim myFormatRng As Range

Sheets("sheet1").Select
Sheets("sheet1").Range("d5").Select

myRow = ActiveCell.Row
myCol = ActiveCell.Column
Set myFormatRng = ActiveSheet.Cells(myRow, myCol)

Do While myFormatRng <> &quot;&quot;
If myFormatRng.Value = &quot;Price&quot; Then
ActiveSheet.Range(Cells(myRow, myCol), Cells(myRow, 26)).Select
Selection.NumberFormat = &quot;$#,##0.00&quot;
Else
ActiveSheet.Range(Cells(myRow, myCol), Cells(myRow, 26)).Select
Selection.NumberFormat = &quot;#,##0&quot;
End If

myRow = myRow + 1
Set myFormatRng = ActiveSheet.Cells(myRow, myCol)

Loop

End Sub


Hope this helps.

rgrds
LSTAN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top