• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Formula to be simplified

.Formula = "=IF(ISERROR(HLOOKUP(E$5,'Append Pivot'!$H" & startThirdPivot & ":$BP" & (reason_count + startThirdPivot) & ",$A" & row & ",FALSE))=FALSE,IF(ABS(HLOOKUP(E$5,'Append Pivot'!$H" & startThirdPivot & ":$BP" & (reason_count + startThirdPivot) & ",$A" & row & ",FALSE))<2, " & quote & quote & ", HLOOKUP(E$5,'Append Pivot'!$H" & startThirdPivot & ":$BP" & (reason_count + startThirdPivot) & ",$A" & row & ",FALSE))," & quote & quote & ")"
 
Assumptions based on your other threads:
quote = "
startThirdPivot is a number
row is a number
reason_count is a number
 
It's pretty reduced already in terms of formula structure , but to make it easier to read the code, you could do:
Code:
Dim fString As String
Dim myFormula
fString = "HLOOKUP(E$5,'Append Pivot'!$H" & startThirdPivot & ":$BP" & (reason_count + startThirdPivot) & ",$A" & row & ",)"
myFormula = "=IF(ISERROR(" & fString & "),"""",IF(ABS(" & fString & ")<2,""""," & fString & "))"
.Formula = myFormula
By building the formula as a string first, you can more easily debug and see what the actual string looks like before trying to plug it into the formula. By using an extra variable to hold the HLOOKUP bit, I think it makes the longer formula a little easier to read.
 
Back
Top