LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
tb tb is offline
external usenet poster
 
Posts: 84
Default Excel Macro: Type mismatch (Error 13)

On 1/8/2018 at 2:10:26 PM GS wrote:

On 1/6/2018 at 7:56:51 AM GS wrote:

Oops.., didn't fully cleanup after testing! The working code
follows...

Sub RoundCurrencyValues()
Dim rng As Range, crng
On Error Resume Next 'in case no Range("pctChange")
Set rng = ActiveSheet.Range("pctChange")
If Not rng Is Nothing Then
For Each crng In ActiveSheet.UsedRange.Cells
If crng.NumberFormat = sCurrencyFormat Then crng.Value =
WorksheetFunction.Round(crng * (1 + rng), 2) Next 'crng
End If 'Not rng Is Nothing
Set rng = Nothing
End Sub


Thanks I will try the code out. I'm having problems understanding
how to declare "pctChange" with local scope. I've never created a
macro myself and cannot find an example of such declaration with
Google.

The best example that I could find about scope declaration is this:
<http://www.cpearson.com/excel/scope.aspx
but it does not seem to address the local scope...


On the Formulas tab, use *Name Manager* and set the scope to the
%cell on the sheet that's active. Activate the next sheet and select
its %cell and repeat.


Garry:

Your macro seems to work fine. The only problem that I've found is
that it puts a "$0.00" in every blank cell that is formatted as
currency. If a cell is blank (and is formatted as currency), I'd like
it to stay so.

Below is the complete macro as you created it for me. Would you mind
seeing if it can be modified as per the above requirement? Also why is
there a "$" character in constant "sCurrencyFormat$"?

*****
Option Explicit

Const sCurrencyFormat$ = "$#,##0.00_);($#,##0.00)"

Sub RoundCurrencyValues()
Dim rng As Range, crng
On Error Resume Next 'in case no Range("pctChange")
Set rng = ActiveSheet.Range("pctChange")
If Not rng Is Nothing Then
For Each crng In ActiveSheet.UsedRange.Cells
If crng.NumberFormat = sCurrencyFormat Then crng.Value =
WorksheetFunction.Round(crng * (1 + rng), 2)
Next 'crng
End If 'Not rng Is Nothing
Set rng = Nothing
End Sub
*****

Thanks.
--
tb
 
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
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
Error type mismatch in writing macro ub Excel Worksheet Functions 2 September 26th 07 12:48 PM
Macro error type mismatch Jurassien Excel Discussion (Misc queries) 3 February 23rd 07 08:14 PM
type mismatch error in Benford's law macro Sody Excel Programming 1 May 24th 06 11:07 PM
Visual Basic macro run time error(13) type mismatch Paul Excel Discussion (Misc queries) 0 October 25th 05 07:28 AM


All times are GMT +1. The time now is 08:52 AM.

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"