PDA

View Full Version : [SOLVED:] Copy/Paste formula using lastcolumn



jerryr0125
05-31-2017, 05:42 PM
hi -
I am looking for a way to do the following :
- Analyze row 1 in a spreadsheet
- Determine the number of columns (the last column)
- copy a particular formula from cell AG2 to the last column as calculated (say AZ) in row 2.
I know I have to use something like the following, but in my formula how do I state to copy AG2 to lastcolumn row 2 ?

thanks - jerryr

Dim lCol As Long

lCol = Cells(1, Columns.Count).End(xlToLeft).Column

SamT
05-31-2017, 06:36 PM
Something that looks like

AG2 Copy
Cells(2, lcol).PasteSpecial xlpasteformulas

However, depending on how the formula is written it may not work there like it does in AG2

mdmackillop
06-01-2017, 03:22 AM
Different interpretation

Dim lCol As Long
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, "AG"), Cells(2, lCol)).FillRight