find and convert/format dates and dollar values

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100
Is there a way in VBA to find Date and Dollar values on imported data and set the appropriate formatting?
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Using Excel 2003 with data from Access using either 1) Query -Tools, Office Links, Analyze with Excel or 2) the DoCmd.OutputTo acQuery… MicrosoftExcelBiff8(*.xls) from within Access
<o:p></o:p>
I am in the process of creating report specific macros’ for our teams users that do a lot of formatting on each query and turn it into a report, but am wondering if there is a better way. Now I create a macro to manually select and format the columns that have date values and the same for dollar values. I have to go through each report and code these columns in, and also go back and update with changes. Users can run these from an add-in any time they want against the imported data.
<o:p></o:p>
Is there a way to go through a workbook and find cells with dates and convert them if needed and set the date format? Most come up as dates but some as text. The two formats I start with are either d/mm/yy (as date or text) and dd-mmm-yy (as date or text). These I change to dd/mm/yyyy.
<o:p></o:p>
So far dollar values always seem to be as numbers in “#,##0.00;(#,##0.00)” format. and I just change the format of these to "$#,##0.00_);[Red]($#,##0.00)"
<o:p></o:p>
Here are samples of what I do now:
<o:p></o:p>
Rich (BB code):
Columns("E:AD").Select
Selection.ColumnWidth = 13.5<o:p></o:p>
Selection.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)
 
<o:p></o:p>
Columns("W:Z").Select<o:p></o:p>
 Selection.NumberFormat = "mm/dd/yyyy;@"<o:p></o:p>
 Selection.HorizontalAlignment = xlCenter
 Selection.ColumnWidth = 10.5"
<o:p></o:p>
Dollars are always 13.5 and dates 10.5 users don’t like autofit as they want columns to look uniform
<o:p></o:p>
Thanks for suggestions!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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