Autofill specific range which is dynamic

sourabh_ajmera

New Member
Joined
Jul 17, 2014
Messages
36
Hello Everybody,

I need your help in correcting this code. I need a range from specific row to specific column.
The row and column has to be dynamic as it changes everyday. I have been through few posts on this but nothing what fullfilled my requirement.

Code:

'Last Column
Dim col As Integer
col = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
MsgBox col

'Last Row
Dim row As Long
row = Cells.Find("*", [A1], , , xlByRows, xlPrevious).row
MsgBox row

ActiveWorkbook.Names("td").RefersToR1C1 = "=TD!R1C1:R" & row & "C" & col & ""
ActiveWorkbook.Names("titletd").RefersToR1C1 = "=TD!R1C11:R1C" & (col - 14) & ""

Range("FU2").Select
ActiveCell.Formula = _
"=IFERROR(AVERAGEIFS(RC11:RC165,titletd,"">=""&MONTH(R1C)&""/1/""&YEAR(R1C),titletd,""<=""&MONTH(R1C)&""/""&DAY(DATE(YEAR(R1C),MONTH(R1C)+1,0))&""/""&YEAR(R1C)),0)"


Selection.AutoFill Destination:=Range(Cells(2, (col - 6)), Cells(2, col)).Select, Type:=xlFillDefault <--- This is where I need help to make it dynamic

'Selection.AutoFill Destination:=Range("FU2:GA2"), Type:=xlFillDefault <--- This is the range

Any suggestions? Please help even if its a small mistake.
Thank you in advance.
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This works, I am not sure why it is needed.
Code:
    col = 183 'GA   1877=FU
    Range("FU2").AutoFill Destination:=Range("FU2:GA2"), Type:=xlFillDefault
    Range("FU2").AutoFill Destination:=Range(Range(Cells(2, (col - 6)), Cells(2, col)).Address), Type:=xlFillDefault
 
Upvote 0
Thanks @pbornemeier....it works!!

I also came up with another solution

Found out the column header name and converted that into column no and than to column letter
same with the last column. Found out the last column and converted it into column letter and then used it as below:

Code:
Selection.AutoFill Destination:=Range(JanCol3 & "2:" & coltxt3 & "2"), Type:=xlFillDefault
 
Upvote 0

Forum statistics

Threads
1,216,759
Messages
6,132,555
Members
449,735
Latest member
Gary_M

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