VBA change the format of a cell from account to custom %

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, i was curious if there is a way to use VBA to change to format of a cell(s) from accounting to custom type 0%
Saying i have a sheet 1, cell D15 and D16 these are both accounting but wanting them to change from that to custom 0%
thank you!
1649436136522.png
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Are you aware that there is a macro recorder that can teach you quite a bit about creating code?
I'd start the recorder, select the cells, press ctrl+1, set the format, OK, stop recording then select that new macro and click edit to see what's there.
I believe you need to have enabled the Developer tab on the ribbon first.
 
Upvote 0
Are you aware that there is a macro recorder that can teach you quite a bit about creating code?
I'd start the recorder, select the cells, press ctrl+1, set the format, OK, stop recording then select that new macro and click edit to see what's there.
I believe you need to have enabled the Developer tab on the ribbon first.
I did not i will look into this thank you
 
Upvote 0
Are you aware that there is a macro recorder that can teach you quite a bit about creating code?
I'd start the recorder, select the cells, press ctrl+1, set the format, OK, stop recording then select that new macro and click edit to see what's there.
I believe you need to have enabled the Developer tab on the ribbon first.
This is awesome, it helps out a lot better understanding some of the items i want to do that are simple to do in excel but wasnt sure how to do in VBA! Thank you so much! I now need to see how i can do it for a specific sheet probably dimming the sheet, but would need to check out how do to do so as this will get implemented towards a specific worksheet

VBA Code:
    Range("AG249:AH249").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("AG249").Select
    ActiveCell.FormulaR1C1 = "United States"
    Range("AH249").Select
    ActiveCell.FormulaR1C1 = "US"
    Range("AH250").Select
 
Upvote 0
If the code is created in a sheet module, you usually don't have to specify the sheet by name, AFAIK. If it was saved in a general module and refers to a selection, it will work for any sheet, which is not always what you need. Also, some of what the macro recorder captures is fluff as you stumble through what it is you're interacting with. In your case it could be as simple as specifying the sheet, as in
Sheets("Sheet1").Range("AG249:AH249").Select

or something similar. One thing you'll need to keep in mind is that references are relative to where the code is located if you don't specify otherwise.
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,959
Members
452,539
Latest member
delvey

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