• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Copying to column to last row of data in column D

Teatimedgg

New Member
Hi everyone, Still new! but learning with everyone's help :)

I have data in columns D and G and I am adding a formula in Columns A, B, C, E, F and J. I want to make sure the formula columns go to the end of the data in Column D when I copy it down.

Example:

See attached

I want columns to use column D to know where to copy the formula down to.


thanks!!
 

Attachments

  • Test data for copy to end of column.xlsx
    8.7 KB · Views: 10
Hi everyone, Still new! but learning with everyone's help :)

I have data in columns D and G and I am adding a formula in Columns A, B, C, E, F and J. I want to make sure the formula columns go to the end of the data in Column D when I copy it down.

Example:

See attached

I want columns to use column D to know where to copy the formula down to.


thanks!!
Code:
Sub Demo
   Dim ws As Worksheet
       With ws.[D3].Resize(ws.Cells(Rows.Count, 3).End(xlUp).Row)




'Since rows 1 and 2 are blank (potential header rows?), the D3
'  (above) tells this Subroutine to start in the 3rd row.  It
' will continue until it runs out of data in D.

'  Someone more expert than I, please confirm.


'   Y O U R   L O G I C   G O E S   H E R E.


      End With
End Sub
 
Last edited:
maybe something like this:

Code:
Option Explicit

Sub InsertFormula()
Dim lr As Long
lr = Range("D" & Rows.Count).End(xlUp).Row
Range("J3").FormulaR1C1 = "=RC[-3] * 5" 'Insert your own formula here
Range("J3:J" & lr).FillDown
End Sub
 
maybe something like this:

Code:
Option Explicit

Sub InsertFormula()
Dim lr As Long
lr = Range("D" & Rows.Count).End(xlUp).Row
Range("J3").FormulaR1C1 = "=RC[-3] * 5" 'Insert your own formula here
Range("J3:J" & lr).FillDown
End Sub
Hi ,

The code can be simplified further to :
Code:
Sub InsertFormula()
    Dim lr As Long
    lr = Range("D" & Rows.Count).End(xlUp).Row
    Range("J3:J" & lr).Formula = "=G3 * 5" 'Insert your own formula here
End Sub
Narayan
 
Back
Top