Resize based on activecell offset and last row

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

After some searching I found the below that gets me close to my objective. How would I incorporate offset in the code? Meaning, if my active cell is C3, how could I copy activecell.offset(-1,0), in this example C2 and autofill to the last row?

VBA Code:
LR = Range("B" & Rows.count).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range(ActiveCell.Address & ":C" & LR)

I tried
VBA Code:
ActiveCell.Offset(-1, 0).AutoFill Destination:=Range(ActiveCell.Address & ":C" & LR)

In the below I would copy Yes from C2 to C3:C20
.xlsm
ABC
1
2INFOYES
3INFO
4INFO
5INFO
6INFO
7INFO
8INFO
9INFO
10INFO
11INFO
12INFO
13INFO
14INFO
15INFO
16INFO
17INFO
18INFO
19INFO
20INFO
Sheet11

Thank you,
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You do not need Autofill. You can apply any value or formula to a whole range at once, i.e.
VBA Code:
LR = Range("B" & Rows.Count).End(xlUp).Row
Range("C2:C" & LR).Value = "YES"
 
Upvote 0
You do not need Autofill. You can apply any value or formula to a whole range at once, i.e.
VBA Code:
LR = Range("B" & Rows.Count).End(xlUp).Row
Range("C2:C" & LR).Value = "YES"
Thank you but the value can change as can the location of the active cell in column C. It needs to be dynamic, no matter which cell is active in column C, the macro will copy the cell above and fill down to the last row based on column B.
 
Upvote 0
You can use this, which I have documented to describe what each step is doing:
VBA Code:
    Dim LR As Long
    Dim C As Long
    Dim R As Long
    
'   Find current column and row
    C = ActiveCell.Column
    R = ActiveCell.Row
    
'   Find last row in column to the left of active cell
    LR = Cells(Rows.Count, C - 1).End(xlUp).Row

'   Fill column from activecell to last row
    Range(Cells(R, C), Cells(LR, C)).Value = ActiveCell.Offset(-1, 0).Value
 
Upvote 0
Solution
You can use this, which I have documented to describe what each step is doing:
VBA Code:
    Dim LR As Long
    Dim C As Long
    Dim R As Long
   
'   Find current column and row
    C = ActiveCell.Column
    R = ActiveCell.Row
   
'   Find last row in column to the left of active cell
    LR = Cells(Rows.Count, C - 1).End(xlUp).Row

'   Fill column from activecell to last row
    Range(Cells(R, C), Cells(LR, C)).Value = ActiveCell.Offset(-1, 0).Value
Brilliant, thank you very much.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,636
Members
449,109
Latest member
Sebas8956

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