-
Nov 10th, 2020, 12:23 PM
#1
Thread Starter
Fanatic Member
Date Type Mismatch
This just started happening out of the blue. I believe the Excel Data is a date...
Type Mismatch Error 13 on this line:
Code:
startdate = ThisWorkbook.ActiveSheet.Cells(i2, 10).Value
Code:
Dim startdate As Date
If Len(ThisWorkbook.ActiveSheet.Cells(i2, 10).Value) > 0 Then
startdate = ThisWorkbook.ActiveSheet.Cells(i2, 10).Value
End If
Thanks!
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Nov 10th, 2020, 12:38 PM
#2
Re: Date Type Mismatch
Originally Posted by ssabc
This just started happening out of the blue. I believe the Excel Data is a date...
Debugging is the act of comparing your belief against reality.
Good luck.
-
Nov 10th, 2020, 12:41 PM
#3
Fanatic Member
Re: Date Type Mismatch
You have "i"2 instead of 12
HTH
-
Nov 10th, 2020, 12:57 PM
#4
Thread Starter
Fanatic Member
Re: Date Type Mismatch
i2 is the row number, 10 is the column. That is where the dates are located. In debug, it shows a date! But says its the wrong data type.
Last edited by ssabc; Nov 10th, 2020 at 01:19 PM.
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Nov 10th, 2020, 02:33 PM
#5
Re: Date Type Mismatch
What happens if you try this:
Code:
startdate = CDate(ThisWorkbook.ActiveSheet.Cells(i2, 10).Value)
-
Nov 10th, 2020, 03:02 PM
#6
Thread Starter
Fanatic Member
Re: Date Type Mismatch
Oh I've tried that! Same issue
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Nov 10th, 2020, 03:15 PM
#7
Re: Date Type Mismatch
Originally Posted by ssabc
i2 is the row number, 10 is the column. That is where the dates are located. In debug, it shows a date!
What, exactly, does it show? Note that something like "November 10, 2020" is a date to the human eye, but to a computer it is a String and not a Date value.
-
Nov 10th, 2020, 05:50 PM
#8
Thread Starter
Fanatic Member
Re: Date Type Mismatch
Originally Posted by OptionBase1
What, exactly, does it show? Note that something like "November 10, 2020" is a date to the human eye, but to a computer it is a String and not a Date value.
11/20/2020. The format is in fact, correct.
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Nov 10th, 2020, 06:10 PM
#9
Re: Date Type Mismatch
Well, I just did some limited testing and pointed identical code to what you posted at different cells formatted as a Date, Text, preceded with a ', etc with a date of 11/10/2020 and couldn't get it to fail.
Without further details (like an example spreadsheet that exhibits the behavior reported), the next most logical conclusion is that the cell you think it is referencing isn't the cell that is actually being referenced.
I can't assist further. Good luck.
-
Nov 10th, 2020, 07:23 PM
#10
Re: Date Type Mismatch
What do you get with this code:
Code:
Debug.Print ThisWorkbook.ActiveSheet.Cells(i2, 10).Value
-
Nov 10th, 2020, 10:37 PM
#11
Fanatic Member
Re: Date Type Mismatch
Going back to my post #3.
A Cell takes a reference of Cell(row, column).
Excel used to refer to rows by numbers (1 to ...) and columns by Letters (A, B, C, ....)
So a single Cell reference would be something like Cell(12, K) -- or 12K without the Keyword Cell
I've never seen a single row referenced as a letter number combination such as i2
-
Nov 11th, 2020, 01:29 AM
#12
Re: Date Type Mismatch
vb6, have you considered that i2 is probably a numeric variable that is being used to do something like loop through rows?
-
Nov 11th, 2020, 02:07 AM
#13
Re: Date Type Mismatch
That blasted "Active"-Something again.
Is your "Active"-Sheet even the "correct" one?
Does the error happen, when you qualify the sheet directly (via number/Name)?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 11th, 2020, 03:27 AM
#14
Re: Date Type Mismatch
try dimensioning startdate as a variant, step through the code to that line (or put a break point) then in the locals window you will be able to look at the variable to see what type visual basic thinks it should be and whether the value it has, matches what you expect
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 11th, 2020, 08:19 AM
#15
Fanatic Member
Re: Date Type Mismatch
OptionBase1:
vb6, have you considered that i2 is probably a numeric variable that is being used to do something like loop through rows?
My Error -- Thanks for pointing it out. I use variables all the the time for row or column, but for whatever reason never made the connection "i2" could be a row variable, maybe because of the hardcoded "10"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|