Code not placing the formula in the selected cells

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have this code below that is suppose to place a lookup formula down each one of the column,

When I run the code it is only placing the formula in the first row (11).

I know my last row is 51 and I know the code is determining the correct last row because I can see its selecting E11:E51
Its just not putting the formula in each row.

This code was running fine until today

Code:
Sub AutofillAssocPartData()
'Auto-populate the associated fields: Description, Rev, UM and Commodity

MsgBox "If the listed part exisit in Costpoint, this will pull in the associated Description, Rev, UM and Commodity"

Dim LRow As Long


LRow = Sheets("Part List").Cells(Rows.Count, "B").End(xlUp).Row


   Sheets("Part List").Select
    Range("C11:C" & LRow).Activate
    ActiveCell.FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[ItemDescription])),"""")"
    Range("D11:D" & LRow).Select
    ActiveCell.FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[LastRevisionID])),"""")"
    Range("E11:E" & LRow).Select
    ActiveCell.FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[DefaultUnitofMeasureCode])),"""")"
    Range("F11:F" & LRow).Select
    ActiveCell.FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[Commodity])),"""")"

    
  '  Sheets("Part List").Select
  '  Range("C11:F" & LRow).Select
  '   Selection.Copy
  '  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  '      :=False, Transpose:=False
  '  Application.CutCopyMode = False
  '  Calculate

 'Sheets("Part List").Select
 '   Range("B11").Select

End Sub

Thanks for the help
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The problem is ActiveCell is just a single cell, not a multi-cell range!
You are selecting the whole range, but then just applying the formula to the ActiveCell (which will only be the first cell in your range).

There is no reason to select the cells or try to use ActiveCell at all. Just set the range values directly by turning all structures like this:
VBA Code:
    Range("C11:C" & LRow).Activate
    ActiveCell.FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[ItemDescription])),"""")"
into this:
VBA Code:
    Range("C11:C" & LRow).FormulaR1C1 = _
        "=IFNA((XLOOKUP([@[Part List]],ModelGeneral_vluItem[ItemID],ModelGeneral_vluItem[ItemDescription])),"""")"
Do that to all of the rest too.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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