View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steve Garman Steve Garman is offline
external usenet poster
 
Posts: 107
Default Type mismatch

TIM wrote:
I get run time error 13
type mismatch
from this line of code in VB

Cells(cLastRow + 1, "B").Value = Cells(cLastRow, "B").Value + 1


is cLastRow a number?

my first two tests work OK herehe

Sub test()
Dim cLastRow As Long
cLastRow = 7
Cells(cLastRow + 1, "B").Value = Cells(cLastRow, "B").Value + 1
End Sub

Sub test2()
Dim cLastRow As String
cLastRow = "7"
Cells(cLastRow + 1, "B").Value = Cells(cLastRow, "B").Value + 1
End Sub

test3, not surprisingly, produces a type mismatch

Sub test3()
Dim cLastRow As String
cLastRow = "G"
Cells(cLastRow + 1, "B").Value = Cells(cLastRow, "B").Value + 1
End Sub


--
Steve Garman