Number Format

tquist

Board Regular
Joined
Jul 18, 2008
Messages
53
I can't seem to get a cell formated the way I want. I would like to format ActiveCell.Offset(2, 0) as a percentage. I keep getting an error saying "unable to set the NumberFormat property of the Range class. Any suggestions? The problem area is at the end of the code...

Code:
Sub TablePopulator()
'
' Statistics and Chart Source Table Generator Macro by Tom Quist
'
Dim Jurisdictions As Range
Dim Cartersville As Range
Dim Responses As Range
Set Responses = Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(17, 0))
Set Cartersville = Application.InputBox(prompt:="Select the Cartersville Value", Title:="Cartersville", Type:=8)
Set Jurisdictions = Application.InputBox(prompt:="Select the Jurisdictions Range", Title:="Jurisdictions", Type:=8)
ActiveCell.Offset(1, 0) = "=if(isnumber(" & Cartersville.Address(external:=True) & "), (" & Cartersville.Address(external:=True) & "), NA())"
ActiveCell.Offset(2, 0) = "=if(isnumber(" & Cartersville.Address(external:=True) & "), Percentrank(" & Jurisdictions.Address(external:=True) & "," & Cartersville.Address(external:=True) & "),"""")"
ActiveCell.Offset(3, 0) = "=Median(" & Jurisdictions.Address(external:=True) & ")"
ActiveCell.Offset(4, 0) = "=count(" & Jurisdictions.Address(external:=True) & ")"
ActiveCell.Offset(5, 0) = "=Max(" & Jurisdictions.Address(external:=True) & ")"
ActiveCell.Offset(6, 0) = "=Min(" & Jurisdictions.Address(external:=True) & ")"
ActiveCell.Offset(7, 0) = "=Percentile(" & Jurisdictions.Address(external:=True) & ",.1)"
ActiveCell.Offset(8, 0) = "=Percentile(" & Jurisdictions.Address(external:=True) & ",.25)"
ActiveCell.Offset(9, 0) = "=Percentile(" & Jurisdictions.Address(external:=True) & ",.75)"
ActiveCell.Offset(10, 0) = "=Percentile(" & Jurisdictions.Address(external:=True) & ",.9)"
ActiveCell.Offset(11, 0) = "=(" & ActiveCell.Offset(8, 0).Address(external:=True) & ")"
ActiveCell.Offset(12, 0) = "=(" & ActiveCell.Offset(3, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(8, 0).Address(external:=True) & ")"
ActiveCell.Offset(13, 0) = "=(" & ActiveCell.Offset(9, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(3, 0).Address(external:=True) & ")"
ActiveCell.Offset(14, 0) = "=(" & ActiveCell.Offset(8, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(6, 0).Address(external:=True) & ")"
ActiveCell.Offset(15, 0) = "=(" & ActiveCell.Offset(5, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(9, 0).Address(external:=True) & ")"
ActiveCell.Offset(16, 0) = "=(" & ActiveCell.Offset(3, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(7, 0).Address(external:=True) & ")"
ActiveCell.Offset(17, 0) = "=(" & ActiveCell.Offset(10, 0).Address(external:=True) & ") - (" & ActiveCell.Offset(3, 0).Address(external:=True) & ")"
Responses.Font.Size = 8
ActiveCell.Offset(2, 0).NumberFormat = "Percent"
'
End Sub
 
Whoops! I spoke to soon (not on the thank you part).

The code has formated not only ActiveCell.Offset(2, 0) as a percentage, but also ActiveCell.Offset(1, 0). Any suggestions on how to prevent this?

Thank you!

Tom
 
Upvote 0
Nevermind. I'm an idiot. Scratch that last comment. It DOES work perfectly. You rock.

Tom
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top