Storing and formatting is single operation

TheGREATrandino

New Member
Joined
Sep 9, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Is it possible to store and format a value to a cell in a nested statement in excel vba?
For example,
Range("A2").value = 123445.34
range("A2").NumberFormat="#,##0.00"
both statements work and produce the desired results. How do you do something like Range("A2").value = 123445.34, format "#,##0.00"
Is it "better" to set the formatting in VBA or through the GUI on the sheet?

TIA
Randino
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

TheGREATrandino

New Member
Joined
Sep 9, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
figured it out!!!!!
Is it bad to answer your own post?

Range("A2").Value = 123445.34
Range("A2").Value = Format(Range("A2"), "#,##0.00")
Format is a Function and requires a number or an expression (Range("A2")) is this example, and a formatting "template" ("#,##0.00)
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,949
Office Version
  1. 365
Platform
  1. Windows
Is it bad to answer your own post?
Not at all.
As matter as fact, we encourage it. That way if someone else down the road has the same issue/question, and find this thread, they can see what the solution is.
 

Forum statistics

Threads
1,141,051
Messages
5,703,967
Members
421,321
Latest member
blusky4

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
Top