Hi everyone,
I am quite stuck in troubleshooting my macro to fix a runtime error 13 Type mismatch problem. Below are pertinent excerpts from my code:
Dim HHYear As Variant
Dim HAccount As Variant
Dim HAmpersan As Variance
HAmpersan = Chr(38)
Cells.Find(What:="HPVAL", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
HScenario = HComma & HQuote & "Scenario" & HHash & Worksheets("Sheet6").Range("A2").Value & HQuote
HHYear = HComma & HQuote & "Year" & HHash & HAmpersan & "D22" & HAmpersan & HQuote & HQuote
HHPeriod = HComma & HQuote & "Period" & HHash & Worksheets("Sheet6").Range("D21").Value & HQuote
HView = HComma & HQuote & "View" & HHash & Worksheets("Sheet6").Range("D2").Value & HQuote
HEntity = HComma & HQuote & "Entity" & HHash & Worksheets("Sheet6").Range("E2").Value & HQuote
HValue = HComma & HQuote & "Value" & HHash & Worksheets("Sheet6").Range("F2").Value & HQuote
HICP = HComma & HQuote & "ICP" & HHash & Worksheets("Sheet6").Range("G2").Value & HQuote
HCustom1 = HComma & HQuote & "Custom1" & HHash & Worksheets("Sheet6").Range("H2").Value & HQuote
HCustom2 = HComma & HQuote & "Custom2" & HHash & Worksheets("Sheet6").Range("I2").Value & HQuote
HActivityType = HComma & HQuote & "ActivityType" & HHash & Worksheets("Sheet6").Range("J2").Value & HQuote
HProduct = HComma & HQuote & "Product" & HHash & Worksheets("Sheet6").Range("K2").Value & HQuote
HLedgerType = HComma & HQuote & "LedgerType" & HHash & Worksheets("Sheet6").Range("L2").Value & HQuote
HAccount = HComma & HQuote & "Account" & HHash & HQuote & HAmpersan & Cells(ActiveCell.Row, 3).Address & HAmpersan & HQuote & HQuote
HPartA = HEqual & "HsGetValue(" & HConnect & HScenario & HYear & HPeriod & HView & HEntity & HValue & HAccount & HICP & HCustom1 & HCustom2 & HActivityType & HLedgerType & HProduct & ")"
Essentially, I am trying to replace where cell value is "HPVAL" with another formula with a different syntax. The bold lines above are giving me grief. The syntax of the formula requires that it generate an output like "&D2&"". Interestingly, the error only throws up for HHYear and not HAccount even though the output is the same.
I have also tried on two different Excel 2010 patch levels and still get the same result. In reading other postings, it seems that "&D2&"" could be misinterpreted as a "range" or another data type? Originally I had set HHYear as String but changed to Variant in hopes to troubleshoot.
Suggestions?
I am quite stuck in troubleshooting my macro to fix a runtime error 13 Type mismatch problem. Below are pertinent excerpts from my code:
Dim HHYear As Variant
Dim HAccount As Variant
Dim HAmpersan As Variance
HAmpersan = Chr(38)
Cells.Find(What:="HPVAL", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
HScenario = HComma & HQuote & "Scenario" & HHash & Worksheets("Sheet6").Range("A2").Value & HQuote
HHYear = HComma & HQuote & "Year" & HHash & HAmpersan & "D22" & HAmpersan & HQuote & HQuote
HHPeriod = HComma & HQuote & "Period" & HHash & Worksheets("Sheet6").Range("D21").Value & HQuote
HView = HComma & HQuote & "View" & HHash & Worksheets("Sheet6").Range("D2").Value & HQuote
HEntity = HComma & HQuote & "Entity" & HHash & Worksheets("Sheet6").Range("E2").Value & HQuote
HValue = HComma & HQuote & "Value" & HHash & Worksheets("Sheet6").Range("F2").Value & HQuote
HICP = HComma & HQuote & "ICP" & HHash & Worksheets("Sheet6").Range("G2").Value & HQuote
HCustom1 = HComma & HQuote & "Custom1" & HHash & Worksheets("Sheet6").Range("H2").Value & HQuote
HCustom2 = HComma & HQuote & "Custom2" & HHash & Worksheets("Sheet6").Range("I2").Value & HQuote
HActivityType = HComma & HQuote & "ActivityType" & HHash & Worksheets("Sheet6").Range("J2").Value & HQuote
HProduct = HComma & HQuote & "Product" & HHash & Worksheets("Sheet6").Range("K2").Value & HQuote
HLedgerType = HComma & HQuote & "LedgerType" & HHash & Worksheets("Sheet6").Range("L2").Value & HQuote
HAccount = HComma & HQuote & "Account" & HHash & HQuote & HAmpersan & Cells(ActiveCell.Row, 3).Address & HAmpersan & HQuote & HQuote
HPartA = HEqual & "HsGetValue(" & HConnect & HScenario & HYear & HPeriod & HView & HEntity & HValue & HAccount & HICP & HCustom1 & HCustom2 & HActivityType & HLedgerType & HProduct & ")"
Essentially, I am trying to replace where cell value is "HPVAL" with another formula with a different syntax. The bold lines above are giving me grief. The syntax of the formula requires that it generate an output like "&D2&"". Interestingly, the error only throws up for HHYear and not HAccount even though the output is the same.
I have also tried on two different Excel 2010 patch levels and still get the same result. In reading other postings, it seems that "&D2&"" could be misinterpreted as a "range" or another data type? Originally I had set HHYear as String but changed to Variant in hopes to troubleshoot.
Suggestions?