Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Column Index Name Error in Formula

I am trying to calculate the component q'ty from Sheet Plan to Sheet Result by using Vlookup to fill in column,having:

  • Count_col: is the total column in sheet Plan
  • Last_col: is the total column in sheet Result (before add column Demand)

Sheet Results

Material Component Demand W1 Demand W2
ABCD1000 nc200 #NAME? #NAME?

Sheet Plan

Material Demand W1 Demand W2
ABCD1000 1000 200
    For i = 1 To count_col
        Cells(1, i + last_col).Value = "=Plan!RC[-2]"
        Cells(1, i + last_col).Offset(1, 0).Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Plan!C1:C15,i+1,0)"
    Next i

But the result is name error, I checked the spelling of function is correct and dont know how to fix. Why there is "@" in my formula?

Detail of error

=VLOOKUP($A2,Plan!$A:$O,@i+1,0)
like image 357
Suzie Avatar asked Jun 18 '21 06:06

Suzie


People also ask

Why is my INDEX Match formula not working?

If you believe that the data is present in the spreadsheet, but MATCH is unable to locate it, it may be because: The cell has unexpected characters or hidden spaces. The cell may not be formatted as a correct data type. For example, the cell has numerical values, but it may be formatted as Text.

How do you fix a formula error in Excel?

If you have previously ignored any errors, you can check for those errors again by doing the following: click File > Options > Formulas. For Excel on Mac, click the Excel menu > Preferences > Error Checking. In the Error Checking section, click Reset Ignored Errors > OK.

How can you avoid the name error value?

Preventing #NAME Errors The best way to prevent the #NAME error in Excel is to use the Formula Wizard. When you begin typing a function name in the formula bar, a series of choices will appear in the drop-down. Instead of continuing to type, you can avoid misspelling errors by selecting a function name from the list.

How do I create a dynamic named range with index?

This page shows an example of a dynamic named range created with the INDEX function together with the COUNTA function. Dynamic named ranges automatically expand and contract when data is added or removed. In the example shown, the named range "data" is defined by the following formula: =$A$2:INDEX($A:$A,COUNTA($A:$A))

Where is the description column in the index?

The column "description" could be the 2nd column in the index or the 50th column in the index. Anyones help would be greatly appreciated. Adjust the INDEX Array (A:Z) to fit your data accordingly. Thank you - Works perfect! Adjust the INDEX Array (A:Z) to fit your data accordingly. Click to expand...

Can I use the same index/match formula with static range names?

The same Index/Match formula with static range names works perfectly. The range names are worksheet specific. The following is the problem formula and the respective range names: This is the same formula / range names with a “2” suffix using static range names which works fine. Appreciate any help resolving this issue. Thanks for reading.

Why am I getting a a a name error in Excel?

A #NAME? error occurs if you attempt to use a dynamic array function in an older version of Excel. Please remember that the new functions are only available in Excel 365 and Excel 2021.


Video Answer


1 Answers

i+1 inside "" behaves like a string rather than a variable. Try this.

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Plan!C1:C15," & i + 1 & ",0)"

Also avoid the use of .Select. Your code can be written as

Cells(1, i + last_col).Offset(1, 0).FormulaR1C1 = _
"=VLOOKUP(RC1,Plan!C1:C15," & i + 1 & ",0)"

Recommended Reading: How to avoid using Select in Excel VBA

Also you are mixing R1C1 and A1 style of referencing. I would recommend using one of them. A simple Google search R1C1 vs A1 style will explain what they are.

In R1C1, Plan!C1:C15 needs to be written as Plan!R1C3:R15C3. So your final code would be

Cells(1, i + last_col).Offset(1, 0).FormulaR1C1 = _
"=VLOOKUP(RC1,Plan!R1C3:R15C3," & i + 1 & ",0)"
like image 157
Siddharth Rout Avatar answered Oct 25 '22 23:10

Siddharth Rout