Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel 2007 vba error

Hello-

I have a macro that works perfect in 2003, but 2007 is kicking up a
runtime error '13' "type mismatch". Does anyone have an idea why this
code will no longer work?

Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double


Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
.Cells(Rows.Count, "H").End(xlUp).Offset(-1, 0))
End With
dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal 'This
is the line showing the error
Next rngCurrent
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Excel 2007 vba error

My guess is that one cell (perhaps, H5?) has a string value.

Try it this way:

Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double

Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
.Cells(Rows.Count,
"H").End(xlUp).Offset(-1, 0))
End With

dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
If IsNumeric(rngCurrent.Value) Then
rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal
Else
MsgBox "Cell " & rngCurrent.Address(False, False) _
& "'s value is not a number"
End If
Next rngCurrent
End Sub

HTH,
Bernie
MS Excel MVP


"Sabosis" wrote in message
...
Hello-

I have a macro that works perfect in 2003, but 2007 is kicking up a
runtime error '13' "type mismatch". Does anyone have an idea why this
code will no longer work?

Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double


Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
.Cells(Rows.Count, "H").End(xlUp).Offset(-1, 0))
End With
dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal 'This
is the line showing the error
Next rngCurrent
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Excel 2007 vba error

On May 11, 5:23*pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
My guess is that one cell (perhaps, H5?) has a string value.

Try it this way:

Sub GetTotalA()
* * Dim rngAllValues As Range
* * Dim rngCurrent As Range
* * Dim wks As Worksheet
* * Dim dblTotal As Double

* * Set wks = ActiveSheet
* * With wks
* * * * Set rngAllValues = .Range(.Range("H5"), _
* * * * * * * * * * * * * * * * * .Cells(Rows.Count,
"H").End(xlUp).Offset(-1, 0))
* * End With

* * dblTotal = Application.Sum(rngAllValues)
* * For Each rngCurrent In rngAllValues
* * * * If IsNumeric(rngCurrent.Value) Then
* * * * * * rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal
* * * * Else
* * * * * * MsgBox "Cell " & rngCurrent.Address(False, False) _
* * * * * * * * *& "'s value is not a number"
* * * * End If
* * Next rngCurrent
End Sub

HTH,
Bernie
MS Excel MVP

"Sabosis" wrote in message

...



Hello-


I have a macro that works perfect in 2003, but 2007 is kicking up a
runtime error '13' "type mismatch". Does anyone have an idea why this
code will no longer work?


Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double


Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
*.Cells(Rows.Count, "H").End(xlUp).Offset(-1, 0))
End With
dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
*rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal *'This
is the line showing the error
Next rngCurrent
End Sub- Hide quoted text -


- Show quoted text -


Bernie-

The message box is popping up telling me that the values in H are not
a number. The values in H are a 3 letter division code.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Excel 2007 vba error

Scott,

The message box is popping up telling me that the values in H are not
a number. The values in H are a 3 letter division code.


Could you post examples of your three letter codes and the sum that you
would expect for the examples? Are you actually summing numbers associated
with those values, perhaps in another column?

Bernie
MS Excel MVP


"Sabosis" wrote in message
...
On May 11, 5:23 pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
My guess is that one cell (perhaps, H5?) has a string value.

Try it this way:

Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double

Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
.Cells(Rows.Count,
"H").End(xlUp).Offset(-1, 0))
End With

dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
If IsNumeric(rngCurrent.Value) Then
rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal
Else
MsgBox "Cell " & rngCurrent.Address(False, False) _
& "'s value is not a number"
End If
Next rngCurrent
End Sub

HTH,
Bernie
MS Excel MVP

"Sabosis" wrote in message

...



Hello-


I have a macro that works perfect in 2003, but 2007 is kicking up a
runtime error '13' "type mismatch". Does anyone have an idea why this
code will no longer work?


Sub GetTotalA()
Dim rngAllValues As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Dim dblTotal As Double


Set wks = ActiveSheet
With wks
Set rngAllValues = .Range(.Range("H5"), _
.Cells(Rows.Count, "H").End(xlUp).Offset(-1, 0))
End With
dblTotal = Application.Sum(rngAllValues)
For Each rngCurrent In rngAllValues
rngCurrent.Offset(0, 1).Value = rngCurrent.Value / dblTotal 'This
is the line showing the error
Next rngCurrent
End Sub- Hide quoted text -


- Show quoted text -


Bernie-

The message box is popping up telling me that the values in H are not
a number. The values in H are a 3 letter division code.

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
Excel 2007 error Tanya Excel Discussion (Misc queries) 0 October 13th 09 10:13 AM
Excel 2007 - error saving file & error loading dll TinaF Excel Discussion (Misc queries) 0 July 1st 09 01:49 PM
X error bar Excel 2007 rolando Charts and Charting in Excel 1 March 21st 09 12:01 AM
Error in Excel 2007 Flores Excel Discussion (Misc queries) 1 September 25th 08 06:02 PM
Excel 2007 Error JG2222 Excel Programming 0 August 9th 07 10:58 PM


All times are GMT +1. The time now is 07:16 AM.

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

About Us

"It's about Microsoft Excel"