VBA to skip lines

chrysti

Board Regular
Joined
Dec 20, 2006
Messages
218
I need to write a macro that will reference a cell that I have counted how many rows my data needs to copied down to and stop when it hits that cell number. Example my reference cell ia A1 and it calculates there are 657 cells of data. I want to have my formulas on another tab paste down 657 cells...

Please help.

Thanks in advance
C
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
C,

The below code could be improved and generalized a little more but it does work in my tests. It assumes continuous data on each sheet from A1 as I am using currentRegion to bound the data. Change the base from A1 if needed.

Code:
Sub fillToOtherSheetRow()

    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng2Paste As Range
    
    Dim LR1 As Long
    Dim LR2 As Long
    Dim LC2 As Integer
    
    Set rng1 = Sheets("Sheet1").Range("A1").CurrentRegion
    Set rng2 = Sheets("Sheet2").Range("A1").CurrentRegion

    LR1 = rng1.Row + (rng1.Rows.Count - 1)
    LR2 = rng2.Row + (rng2.Rows.Count - 1)
    LC2 = rng2.Column + (rng2.Columns.Count - 1)
      
    With Sheets("Sheet2")
        Set rng2Paste = .Range(.Cells(LR2 + 1, rng2.Column), .Cells(LR1, LC2))
    End With

    rng2.Rows(rng2.Rows.Count).Copy rng2Paste

End Sub

Too Tired Edit
I am probably to tired to post as I am not sure the above is a solution to the specifics of your problem or not. On first reading I thought it was what you wanted but after posting and rereading your question I am not sure. Either way let me know
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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