copy range across columns to last column

288enzo

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

Is there a method similar to Range("B4:B" & Range("A" & Rows.Count).End(xlUp).Row) that can be used for columns?

I have a formula in B3, I used the above to copy the formula down to the last row. I would now like to copy right to the last column based on row 2.

Basically trying to fill a range last row and last column with the formula in B3.

A is used for the last row
2 is used for the last column

Thank you
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Maybe:
VBA Code:
Sub FillFormula()
Dim Lrw As Long, Lcol As Long
Lrw = Columns(1).Find("*", , , xlByRows, xlPrevious).Row
Lcol = Rows(2).Find("*", , , xlByColumns, xlPrevious).Column
Range("B3:B" & Lrw).FillDown
Range("B3", Cells(Lrw, Lcol)).FillRight
End Sub
Another way that fills the formula but not the format of B3:
VBA Code:
Sub FillFormula2()
Dim Lrw As Long, Lcol As Long
Lrw = Columns(1).Find("*", , , xlByRows, xlPrevious).Row
Lcol = Rows(2).Find("*", , , xlByColumns, xlPrevious).Column
Range("B3", Cells(Lrw, Lcol)).Formula = Range("B3").Formula
End Sub
 
Upvote 0
Maybe:
VBA Code:
Sub FillFormula()
Dim Lrw As Long, Lcol As Long
Lrw = Columns(1).Find("*", , , xlByRows, xlPrevious).Row
Lcol = Rows(2).Find("*", , , xlByColumns, xlPrevious).Column
Range("B3:B" & Lrw).FillDown
Range("B3", Cells(Lrw, Lcol)).FillRight
End Sub
Another way that fills the formula but not the format of B3:
VBA Code:
Sub FillFormula2()
Dim Lrw As Long, Lcol As Long
Lrw = Columns(1).Find("*", , , xlByRows, xlPrevious).Row
Lcol = Rows(2).Find("*", , , xlByColumns, xlPrevious).Column
Range("B3", Cells(Lrw, Lcol)).Formula = Range("B3").Formula
End Sub
I appreciate the help, but neither worked for me.

Here is what the sheet looks like I'm working with.

Area 84 IND Sept-October.xlsx
BCDEFG
2600336A3600336PL600336SSIFU600336SSIVD600336VIQS601036F
38
41
52
64
71
81
91
100
110
120
130
140
150
report
Cell Formulas
RangeFormula
B3:B15B3=COUNTIFS(data!H:H,$A3,data!A:A,B$2)
Named Ranges
NameRefers ToCells
data!_FilterDatabase=data!$A$3:$AI$3B3:B15


I was thinking, from the above and a starting point of B3, create a loop, look +1 column and -1 row, if there is data then copy B3 to last row, paste +1 column.

Thoughts?
 
Upvote 0
Try this, it's a modification of Joe's code. Since you have already done a fill down on column B, I have used column B for the last row to fill right.
(you can change it to A if you want to)
VBA Code:
Sub FillFormula()
    Dim Lrw As Long, Lcol As Long
    Lrw = Cells(Rows.Count, "B").End(xlUp).Row
    Lcol = Cells(2, Columns.Count).End(xlToLeft).Column
    Range("B3", Cells(Lrw, Lcol)).FillRight
End Sub
 
Upvote 0
Solution
Try this, it's a modification of Joe's code. Since you have already done a fill down on column B, I have used column B for the last row to fill right.
(you can change it to A if you want to)
VBA Code:
Sub FillFormula()
    Dim Lrw As Long, Lcol As Long
    Lrw = Cells(Rows.Count, "B").End(xlUp).Row
    Lcol = Cells(2, Columns.Count).End(xlToLeft).Column
    Range("B3", Cells(Lrw, Lcol)).FillRight
End Sub
Thank you very much, it worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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