flexible range

Tody03

New Member
Joined
Jun 21, 2014
Messages
48
I have a table with one column A with several lines. The number of lines in column A varies from time to time.
I wrote a macro (see below) that will write a formula in B1 and drag it down from B1 until the last used cell in column A.
In the attached macro the range is limited until B6. How can i make the range (B1:B6) flexible so that the last cell in B will match to the last cell in column A.

Range("B1").Select
ActiveCell.FormulaR1C1 = "=RC[1]+2"
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B6")
Range("B1:B6").Select
End Sub

thanks
tody
 
how i change your code to be aplicable to columns.
i have the following table.

abcdefghi
1a$126 $118$142$141$114$94
2b$226 $177$179$218$165$165
3c$248 $260$240$260$196$196
4d$184 $182$182$243$206$206

<colgroup><col><col span="6"><col span="3"></colgroup><tbody>
</tbody>

I do not know how many lines will be in the table, i do not know how many columns will be in the table.
I want to write a formula at the end of column b. i want to copy the same formula, on the same line, to column c and all the way to the right till the end of the table.
I tried as you suggested to record a macro but i get fix line number and columns.
Thanks
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
There is a line of code in my post up in reply 2 that shows you how to find the last row with data, looking at a particular column.

To find the last column with data, when looking at a particular row, you can do it like this:
Code:
'Find last column with data in row [COLOR=#ff0000]1[/COLOR]
lCol = Cells([COLOR=#ff0000]1[/COLOR], Columns.Count).End(xlToLeft).Column
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,912
Members
451,601
Latest member
terrynelson55

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