Type mismatch

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Age old problem but darned if I can figure it out. When the line with 2 asterisks runs I get a mismatch error #13. Any help would be greatly apprecaited. Here's the relevant code:

VBA Code:
'Extract year only from course date
cordate = Application.match("Course Date", Range("1:1"), 0)
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For counter2 = 2 To finalrow
curdate = Cells(counter2, cordate)
**yearnum = year(curdate)
Cells(counter2, courseyear) = yearnum
Next counter2

Dim statements:
Code:
Dim curdate As Variant
Dim yearnum As Variant
Dim year As Variant
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Delete the line
VBA Code:
Dim year As Variant
Year is a function, by declaring a variable of the same name you're breaking the function and causing an error.
 
Upvote 0
AWESOME!! That makes perfect sense. I would have figured that out in maybe 10 years. Mega thanks!
 
Upvote 0

Forum statistics

Threads
1,214,070
Messages
6,117,525
Members
448,766
Latest member
00Cameron

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top