Hi all,
I'm having an issue with my VBA code not "finding" the match in the correct column.
When I use the formula =MATCH(MID(Sheet3!A4,13,10)*1,A1:AE1,0)
it gives 2/1/2016 to match the header 2/1/2016, it gets me the value 21 which is Column V on my sheet. This is correct. I'm after the Column number 21 to use in my VBA further along down the line.
The problem is, I'm getting a Run-time error '1004' [Unable to get the Match Property of the WorksheetFuction class] as shown below. or I get Run-time error '13' Type Mismatch if I insert the *1 in Format(Mid(sh3.Range("A4") * 1, 13, 10), "m/d/yyyy")
To recreate the problem, Sheet1'! has Headers columns A1 thru AZ that are 6/1/2014, 7/1/2014, 8/1/2014 ... 12/1/2016, 1/1/2017 etc. Sheet3'!A4 has: Start Date: 2/1/2016
[TABLE="class: grid, width: 700, align: center"]
<tbody>[TR]
[TD="align: center"]Sheet1[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]...[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[TD="align: center"]V[/TD]
[TD="align: center"]...[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]6/1/2014[/TD]
[TD="align: center"]7/1/2014[/TD]
[TD="align: center"]8/1/2014[/TD]
[TD="align: center"]...[/TD]
[TD="align: center"]1/1/2016[/TD]
[TD="align: center"]2/1/2016[/TD]
[TD="align: center"]3/1/2016[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 600, align: center"]
<tbody>[TR]
[TD]Sheet3[/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Start Date: 2/1/2016[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thanks for any assistance.
I'm having an issue with my VBA code not "finding" the match in the correct column.
When I use the formula =MATCH(MID(Sheet3!A4,13,10)*1,A1:AE1,0)
it gives 2/1/2016 to match the header 2/1/2016, it gets me the value 21 which is Column V on my sheet. This is correct. I'm after the Column number 21 to use in my VBA further along down the line.
The problem is, I'm getting a Run-time error '1004' [Unable to get the Match Property of the WorksheetFuction class] as shown below. or I get Run-time error '13' Type Mismatch if I insert the *1 in Format(Mid(sh3.Range("A4") * 1, 13, 10), "m/d/yyyy")
Code:
Dim sh1 As Worksheet
Dim sh3 As Worksheet
Dim rowDt As String
Dim ColNum As String
Set sh1 = Sheets("Sheet1")
Set sh3 = Sheets("Sheet3")
rowDt = Format(Mid(sh3.Range("A4"), 13, 10), "m/d/yyyy") 'Sheet 3 has [B]Start Date: 2/1/2016[/B] which the date is extracted.
ColNum = Application.WorksheetFunction.Match([B]rowDt[/B], sh1.Range("A1:AZ1"), 0) '
To recreate the problem, Sheet1'! has Headers columns A1 thru AZ that are 6/1/2014, 7/1/2014, 8/1/2014 ... 12/1/2016, 1/1/2017 etc. Sheet3'!A4 has: Start Date: 2/1/2016
[TABLE="class: grid, width: 700, align: center"]
<tbody>[TR]
[TD="align: center"]Sheet1[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]...[/TD]
[TD="align: center"]T[/TD]
[TD="align: center"]U[/TD]
[TD="align: center"]V[/TD]
[TD="align: center"]...[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]6/1/2014[/TD]
[TD="align: center"]7/1/2014[/TD]
[TD="align: center"]8/1/2014[/TD]
[TD="align: center"]...[/TD]
[TD="align: center"]1/1/2016[/TD]
[TD="align: center"]2/1/2016[/TD]
[TD="align: center"]3/1/2016[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 600, align: center"]
<tbody>[TR]
[TD]Sheet3[/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Start Date: 2/1/2016[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thanks for any assistance.