Format a cell

M

Michael Smith

Looking to have a macro look through all data in a spreadsheet and
format it based on criteria.
If data is greater than 1 format as $
If data is less than 1 then format as a %.


Thanks in advance!-Mike


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

Sam Wilson

This should give you the right idea:

Sub test()

Dim c As Range
Dim ws As Worksheet
Set ws = ActiveSheet

For Each c In ws.Range("A1",
ws.Cells.SpecialCells(xlCellTypeLastCell).Address)
If c.Value < 1 Then
c.NumberFormat = "0.00%"
Else
c.NumberFormat = "$#,##0.00"
End If

Next c

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top