Formula being inserted as literal

gt93grad

Board Regular
Joined
Dec 7, 2011
Messages
54
Trying to create a formula with VBA that should be resolved in the cell. However, it's treating is as a literal. I developed this line by recording a macro. Here's the line.

I've tried changing the column to General and reactivating, but no luck.

ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-1],SparesOriginsLookup,4,FALSE)),""HKN1"",VLOOKUP(RC[-1],SparesOriginsLookup,4,FALSE))"
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
1. What version of Excel are you using?

2. Try setting the format within the code, just to be sure.

Code:
With ActiveCell
  .NumberFormat = "General"
  .FormulaR1C1 = _
    "=IF(ISERROR(VLOOKUP(RC[-1],SparesOriginsLookup,4,FALSE)),""HKN1"",VLOOKUP(RC[-1],SparesOriginsLookup,4,FALSE))"
End With
 
Upvote 0
That's the thing. Even setting it to general doesn't work. I have to change the formula to use "D7" instead of the RC reference. Then it works. I'm in 2010.
 
Upvote 0
I'm in 2010.
In that case you could simplify your formula to
=IFERROR(VLOOKUP(RC[-1],SparesOriginsLookup,4,FALSE),""HKN1"")
However, that is not related to the problem you are having.

A bit more information might help.
When you are having the problem ..

1. What is the active cell address?

2. What value is in the cell immediately to the left of the active cell?

3. What range does SparesOriginsLookup refer to?

4. Can you confirm that the value you reported as the answer to my Q2 does actually occur in the left hand column of the SparesOriginsLookup range?

5. Can you confirm that if the VLOOKUP returns an answer you want the text "HKN1" returned and not the contents of cell HKN1?

6. Are you running this code on its own or as part of a larger code? If larger, perhaps we need to see all of it.

7. Do you have any 'event' code in the worksheet's module?
 
Last edited:
Upvote 0
Answers:

1. What is the active cell address? E7.

2. What value is in the cell immediately to the left of the active cell? Dummy

3. What range does SparesOriginsLookup refer to? Four columns that look like this:

ItemIDModelNameLocItemOriginAssignment
1131066Prod_SparesUGS11131066HKN1

<tbody>
</tbody><colgroup><col><col><col span="2"></colgroup>



4. Can you confirm that the value you reported as the answer to my Q2 does actually occur in the left hand column of the SparesOriginsLookup range? Yes. Absolutely.

5. Can you confirm that if the VLOOKUP returns an answer you want the text "HKN1" returned and not the contents of cell HKN1? Yes. HKN1 is an ID for a Hong Kong location.

6. Are you running this code on its own or as part of a larger code? If larger, perhaps we need to see all of it. Part of a larger code, but I've separated this for testing.

7. Do you have any 'event' code in the worksheet's module? No.
 
Upvote 0
No, not really. I know how to create a formula with VBA. I'm using the same steps now. The problem is that it's not resolving, as it did before, and I can't figure out why.
 
Upvote 0
Did you try the suggestion I made in your other thread?
 
Upvote 0
Yes, I did. I tried Text and Number, though many of the values are not strictly numbers (they contain alpha characters). Again, changing the reference to D7 vs an R1C1 reference worked, but not sure why.
 
Upvote 0
3. What range does SparesOriginsLookup refer to? Four columns that look like this:

ItemIDModelNameLocItemOriginAssignment
1131066Prod_SparesUGS11131066HKN1

<tbody>
</tbody><colgroup><col><col><col span="2"></colgroup>
Yes, but what sheet is this table on (same sheet as the formula?) and what range (eg K1:N50).



4. Can you confirm that the value you reported as the answer to my Q2 does actually occur in the left hand column of the SparesOriginsLookup range? Yes. Absolutely.
So you have "Dummy" as an ItemID along with values like "1131066"?


What EXACTLY appears in E7 after running the code?


I'm not sure any of these answers is going to resolve the problem, but I'm just trying to built/test a sheet as much like yours as I can get.
 
Upvote 0

Forum statistics

Threads
1,203,218
Messages
6,054,210
Members
444,710
Latest member
napster91192

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