Fill down based on cell value

izet99

New Member
Joined
Nov 5, 2009
Messages
14
Hi,

Need some help modifying formula below.

It's vlookup formula which is placed into Cell H2 and the code copies the formula down to the bottom of the range. What guides the bottom of the range is the reference to the 7th column in the second line of VBA code.


Code:
Sub FillTable()   'Excel VBA to filldown a range

    Range("H2").Value = "=VLOOKUP(G2,$A$2:$B$17,2,0)"
    Range("H2:H" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

End Sub

I would like to modify code to look into specific Cell H4, sheet "Setup".... H4 cell have formula to count number of items from another sheet… so if value of H4 is 53, I would like code above fill down my formula 53 rows.

Any help or suggestion would be greatly appreciated
Regards,
Izet
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If I've understood you correctly, try
Code:
    myvar = Sheets("setup").Range("H4").Value
    Range("H2").Resize(myvar).Formula = "=VLOOKUP(G2,$A$2:$B$17,2,0)"
 
Upvote 0
Hi Weaver,

This is perfect, thank you very much, it works with my vlookup.... however my Array formula get rusty... it just copy first line down...
Code:
Sub FillTable()   'Excel VBA to filldown a range
       
        myvar = Sheets("Setup").Range("G5").Value
    Range("B25").Resize(myvar).FormulaArray = "=IF(ROWS(R25C[1]:RC[1])<=VLOOKUP(R5C6,Setup!R3C4:R18C7,4,FALSE),INDEX(rngWorkScope,SMALL(IF(rngProductLine=R9C4,IF(rngProjectType=R10C4,IF(rngModule=R5C6,IF(rngLevel=R6C6,ROW(rngWorkScope)-ROW(DepotScope!R2C5)+1)))),ROWS(R25C[1]:RC[1]))),"""")"

End Sub

Original Formula:
{=IF(ROWS(C$25:C25)<=VLOOKUP($F$5,Setup!$D$3:$G$18,4,FALSE),
INDEX(rngWorkScope,
SMALL(
IF(rngProductLine=$D$9,
IF(rngProjectType=$D$10,
IF(rngModule=$F$5,
IF(rngLevel=$F$6,
ROW(rngWorkScope)-ROW(DepotScope!$E$2)+1)))),
ROWS(C$25:C25))),"")}

Am I missing something regarding array formula?
 
Upvote 0
Code below seems to work, it fills down array formula.

Code:
Sub FillTable()   'Excel VBA to filldown a range

   
        myvar = Sheets("Setup").Range("G5").Value
    
        Range("B25").FormulaArray = "=IF(ROWS(R25C[1]:RC[1])<=VLOOKUP(R5C6,Setup!R3C4:R18C7,4,FALSE),INDEX(rngWorkScope,SMALL(IF(rngProductLine=R9C4,IF(rngProjectType=R10C4,IF(rngModule=R5C6,IF(rngLevel=R6C6,ROW(rngWorkScope)-ROW(DepotScope!R2C5)+1)))),ROWS(R25C[1]:RC[1]))),"""")"
        
        Range("B25").AutoFill Range("B25:B25" & myvar)
        

End Sub

Thanks a lot for your help.
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
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