ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type mismatch (https://www.excelbanter.com/excel-programming/290328-re-type-mismatch.html)

Steve Garman

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



All times are GMT +1. The time now is 03:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com