View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Excel Monkey[_2_] Excel Monkey[_2_] is offline
external usenet poster
 
Posts: 36
Default Getting around a Mixed Variable Type

That does not work as I need to add the h:
h = h & Target.Row + h & ":"

Your version had:
h = h & format(Target.Row, "0") + h & ":"

If the target has two rows (7 and 8), I want to get 7:8. Your version
creates "7:77::".

Keeping my original code and changing the variable type to variant fails as
well as it passes the correct values to h on the first pass ("7"). But it
fails on Target.Row + h on the second pass/


Thanks

EM

"Eric G" wrote:

How about something like below. Convert the row number to a string before
you do the appending. Use whatever numeric format you like.

Dim h As String

For g = 0 To Target.Rows.Count - 1
If Target.Rows.Count - 1 = 0 Then
h = Format(Target.Row, "0")
Else
h = h & format(Target.Row, "0") + h & ":"
End If
Next

HTH,

Eric

"Excel Monkey" wrote:

I have a loop. Within this loop I have a variable "h" which is appended by
the current version of itself. I am using a delimiter of ":" during each
append. However I keep getting a type mismatch error as I have dimensioned
"h" as a Double. I think adding the ":" triggers the error. I can't change
"h" to a String as the addition logic that creates the appending will not
work. How do I get around this?

Dim h as double

For g = 0 To Target.Rows.Count - 1
If Target.Rows.Count - 1 = 0 Then
h = Target.Row
Else
h = h & Target.Row + h & ":"
End If
Next

Thanks

EM