Macro for Autofill down based on cells to the right

knpaddac

New Member
Joined
Feb 11, 2014
Messages
33
I have attempted to use the macro recorder to do this, however, it just does not do what I want...
I want to create a macro that can be done via my keyboard (let's say ctrl + z) that will do the same as when I double click the corner box.
autofillhandle.jpg
autofillhandle2.jpg

HOWEVER, the macro will only fill to the same number of cells as when I did it with the recorder rather than automatically going to the length of cells on the right.
Can anybody help me on this one?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:
VBA Code:
Sub MyAutoFill()

    Dim lrA As Long
    Dim lrB As Long
    
'   Find last row in column A with data
    lrA = Cells(Rows.Count, "A").End(xlUp).Row

'   Find last row in column B with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    
'   If lrB greater than lrA, copy down values in column A
    If lrB > lrA Then
        Range(Cells(lrA + 1, "A"), Cells(lrB, "A")).Value = Cells(lrA, "A").Value
    End If

End Sub
 
Upvote 0
Try this:
VBA Code:
Sub MyAutoFill()

    Dim lrA As Long
    Dim lrB As Long
   
'   Find last row in column A with data
    lrA = Cells(Rows.Count, "A").End(xlUp).Row

'   Find last row in column B with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
   
'   If lrB greater than lrA, copy down values in column A
    If lrB > lrA Then
        Range(Cells(lrA + 1, "A"), Cells(lrB, "A")).Value = Cells(lrA, "A").Value
    End If

End Sub
Based on how I described the problem, this did work. However, I'm afraid I didnt fully explain it. The data often looks more like this:
autofill1.jpg
and I would like it to fill in like this:
autofill2.jpg
.
 
Upvote 0

Forum statistics

Threads
1,214,393
Messages
6,119,261
Members
448,880
Latest member
aveternik

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