Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Copying a Currency Format?

I am trying to write a macro to copy the format in the current cell and apply
it to all cells in the book that are currently formated as a currency. Any
idea of why the below is not working?

Sub CurrencyCopy()

Dim rng As Range
Dim format As String
format = ActiveCell.NumberFormat
Msg = "This will reformat all cells currently containing a currency
format. Are you sure you wish to proceed?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbYes Then
Set rng = ActiveSheet.UsedRange
For Each cell In rng
If VarType(cell) = vbCurrency Then
ActiveCell.NumberFormat = format
End If
Next cell
End If

'
End Sub



Thanks for the help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Copying a Currency Format?

I looked up VarType in help and it looks like it applies to variables, not
cells. You can probably try this instead:

Instead of:
If VarType(cell) = vbCurrency Then

Do this:
If cell.NumberFormat = "$#,##0.00" Then

I got "$#,##0.00" by formatting a cell to "Currency" and then selecting the
cell and doing a ?activecell.numberformat in the immediate pane to see how
"Currency" is formatted.


"Mike Piazza" wrote:

I am trying to write a macro to copy the format in the current cell and apply
it to all cells in the book that are currently formated as a currency. Any
idea of why the below is not working?

Sub CurrencyCopy()

Dim rng As Range
Dim format As String
format = ActiveCell.NumberFormat
Msg = "This will reformat all cells currently containing a currency
format. Are you sure you wish to proceed?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbYes Then
Set rng = ActiveSheet.UsedRange
For Each cell In rng
If VarType(cell) = vbCurrency Then
ActiveCell.NumberFormat = format
End If
Next cell
End If

'
End Sub



Thanks for the help!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add new currency Symbol in Format/Cell/Currency NOORZAD Excel Discussion (Misc queries) 2 June 22nd 09 07:59 AM
How to format cells in Excel 2007 (i.e. currency format)? DonR Excel Discussion (Misc queries) 2 May 25th 08 11:16 PM
format cells for currency 2450 and have it format to $24.50? Karen C Excel Worksheet Functions 0 October 13th 05 03:21 PM
why does currency format change to number format? Cassie Excel Discussion (Misc queries) 3 March 18th 05 06:57 PM
Conversion from currency value to currency text format Frank Kabel Excel Programming 1 August 18th 04 10:06 PM


All times are GMT +1. The time now is 08:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"