VBA Code for Formula

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for any suggestions for which I will provide feedback.

I am getting an error on the following formula as it's when i added, the "N/A" part for the IFERROR.

Code:
Cells(i, 4).Formula = "= IFERROR( MATCH(TRUE,INDEX(Sheet1!E" & i & ":" & LastColumnLtr & i & "<>0,),0)," & ""N/A" )"

An example of the output will be:
= IFERROR( MATCH(TRUE,INDEX(Sheet1!E5:I5<>0,),0), N/A)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Thanks JoeMo! I still get an error which is as follows: "Compile error: Syntax error:"
 
Upvote 0
Try this:
Code:
Cells(i, 4).Formula = "= IFERROR( MATCH(TRUE,INDEX(Sheet1!E" & i & ":" & LastColumnLtr & i & "<>0,),0)," & Chr(34) & "N/A" & Chr(34) & ")"
 
Upvote 0
Solution
Thanks JoeMo! That worked perfectly!

So I guess whenever you need something in quotes like that you should separate it with "& Chr(34) &"?
 
Upvote 0
I am Joe4. The original response was from JoeMo.

You *can* use multiple sets of double-quotes (2 or 3 sets) when wanting to include literal quotes in a string or formula. Personally, I find it a but clunky and not intuitive (I don't really like the way it looks), and I can never remember exactly how many sets that I need. So I usually elect to use Chr(34), which is the ASCII code for double-quotes.
 
Upvote 0
Hi Joe4, and once again thanks for your help last time.

I'm trying to use you recommendation and I'm getting error message "Run-time error '438:': Object doesn't support this property or method"

Thanks in advance to any assistance as I will provide feedback.

Code:
Sheets("Files").Cells(i, 3).Formula "= CONCATENATE( INDEX( Attributes!$B:$B, MATCH( Files!$C," & i & ", Attributes!$A:$A, 0), 1 ), " & Chr(34) & "."& Chr(34) & ", TEXT(E" & i & "," & Chr(34) & "YYYY.MM.DD" & Chr(34) & "))"


I also tried the following:

Code:
Sheets("Files").Cells(i, 3).Formula "= CONCATENATE( INDEX( Attributes!$B:$B, MATCH( Files!$C," & i & ", Attributes!$A:$A, 0), 1 ), " & """.""" & ", TEXT(E" & i & "," & """YYYY.MM.DD""" & "))"

I have a loop where I'm trying to get the following to occur in a column. Although it's not VBA Code, I put into that format so it's easier to view. Please note that i is for the integer I use to loop.



Next

Code:
For i = 1 to LastRow

= CONCATENATE( INDEX( Attributes!$B:$B, MATCH( Files!$C3, Attributes!$A:$A, 0), 1 ), ".", TEXT(E3, "YYYY.MM.DD"))
= CONCATENATE( INDEX( Attributes!$B:$B, MATCH( Files!$C4, Attributes!$A:$A, 0), 1 ), ".", TEXT(E4, "YYYY.MM.DD"))
.......
.......
= CONCATENATE( INDEX( Attributes!$B:$B, MATCH( Files!$C7, Attributes!$A:$A, 0), 1 ), ".", TEXT(E7, "YYYY.MM.DD"))

Next i
 
Upvote 0
Whatever else is going on, this is wrong:

Code:
... MATCH( Files!$C[B][COLOR="#FF0000"],[/COLOR][/B]" & i ...
 
Upvote 0
When I do that, I assign the formula to a string and then look at it in the Immediate window. You can copy from there and paste into a cell to see if it works.

Code:
  Dim sFrm As String
  
  sFrm = Replace("= CONCATENATE(INDEX(Attributes!$B:$B, MATCH(Files!$C@, Attributes!$A:$A, 0), 1 ), ""."", TEXT(E@, ""YYYY.MM.DD""))", "@", i)
  Debug.Print frm
  Stop ' and look; is it correct?
  Sheets("Files").Cells(i, 3).Formula = sFrm
 
Upvote 0
Thanks so much Shg! That worked perfectly!

I'm also from and in the Great State of Texas!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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