Select row to last column with data and autofill to last row

jocker_boy

Board Regular
Joined
Feb 5, 2015
Messages
83
Hello,

I would like to select cell "E6" to last column with data.
Then autofill to the last row with data in column "D".

I'm new to VBA.

Many thanks for the help.

Gonçalo
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
See if this does what you want:
VBA Code:
Sub MyCopyMacro()

    Dim lr As Long
    
'   Find last row in column D with data
    lr = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Populate column E with formula to pull value from column D
    Range("E6:E" & lr).FormulaR1C1 = "=RC[-1]"
    
End Sub
 
Upvote 0
See if this does what you want:
VBA Code:
Sub MyCopyMacro()

    Dim lr As Long
   
'   Find last row in column D with data
    lr = Cells(Rows.Count, "D").End(xlUp).Row
   
'   Populate column E with formula to pull value from column D
    Range("E6:E" & lr).FormulaR1C1 = "=RC[-1]"
   
End Sub
thanks,

It's similar to that. But it is not the column "E" that i want to fill dow. Is the entire line that i select in first place:
I select E6 to the last column with data, in my excel file is CJ6, but the number of columns is always changing.

I found this:

Sub Macro2()
Range("E6:CJ" & Range("D" & Rows.Count).End(xlUp).Row).FillDown
End Sub

But i would like to make generic and not fix the column "CJ", but instead, the last column with data in row 6.

Thanks.

Gonçalo
 
Upvote 0
OK, that was definitely not communicated clearly by your original post.

Try this:
VBA Code:
Sub MyCopyMacro()

    Dim lr As Long
    Dim lc As Long
    
'   Find last row in column D with data
    lr = Cells(Rows.Count, "D").End(xlUp).Row
    
'   Find last column in row 6 with data
    lc = Cells(6, Columns.Count).End(xlToLeft).Column
    
'   Copy E6 to last column down for all rows
    Range(Cells(6, "E"), Cells(6, lc)).Copy Range(Cells(7, "E"), Cells(lr, "E"))
    
End Sub
If that still does not do what you want, please post examples of your data and expected results for us to see.
That may help clarify any confusion.
 
Upvote 0
Solution
OK, that was definitely not communicated clearly by your original post.

Try this:
VBA Code:
Sub MyCopyMacro()

    Dim lr As Long
    Dim lc As Long
   
'   Find last row in column D with data
    lr = Cells(Rows.Count, "D").End(xlUp).Row
   
'   Find last column in row 6 with data
    lc = Cells(6, Columns.Count).End(xlToLeft).Column
   
'   Copy E6 to last column down for all rows
    Range(Cells(6, "E"), Cells(6, lc)).Copy Range(Cells(7, "E"), Cells(lr, "E"))
   
End Sub
If that still does not do what you want, please post examples of your data and expected results for us to see.
That may help clarify any confusion.
Sorry for the bad explication.
It is working perfect.

Many thanks
 
Upvote 0
You are welcome.

Yes, sometimes things can be hard to explain, and many times an image or two can go a long way in "showing" us what you are looking for.

For future reference, note that MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

There is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,048
Members
449,206
Latest member
Healthydogs

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