Macro copy cell range sheet to sheet

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
473
Office Version
  1. 365
Platform
  1. Windows
Hi would anyone have a macro that would copy data from
Sheet 1 range C1 to F2000 to next available row on sheet 2 column C
but only if data is entered in the row of to column C
and
Sheet 3 range C1 to F2000 to next available row on sheet 4 column C
but only if data is entered in the row of to column C
So as shown in example, data would stop copying at row 20
Thanks

Book1
ABCDEFG
1a1b7
2a2b8
3a3b9
4a4b10
5a5b11
6a6b12
7a7b13
8a8b14
9a9b15
10a10b16
11a11b17
12a12b18
13a13b19
14a14b20
15a15b21
16a16b22
17a17b23
18a18b24
19a19b25
20b26
21b27
22b28
23b29
24b30
25b31
26b32
27b33
28b34
29b35
30b36
Sheet1
 
sorry i dont think its possible for what i want, columns c1 to to f40 all have formulas,
But from c20 the formula found nothing so returns blank, thats where i would like it to stop copying,
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
try this,

VBA Code:
Sub Paste_NextRow()

    Dim wsCopySh1 As Worksheet
    Dim wsPasteSh2 As Worksheet
    Set wsCopySh1 = Sheets("Sheet1")
    Set wsPasteSh2 = Sheets("Sheet2")
    Dim lastRowSh2 As Long
    lastRowSh2 = ThisWorkbook.Sheets("Sheet2").Cells(Rows.Count, 3).End(xlUp).Row + 1
    Dim N As Long
    'N = wsCopySh1.Range("c" & Rows.Count).End(xlUp).Row
    N = wsCopySh1.[match(2,1/(c:c<>""))]
    wsCopySh1.Range("c1:f" & N).Copy
    wsPasteSh2.Range("C" & lastRowSh2).PasteSpecial Paste:=xlPasteValues
    
    '---------------------------------------
    
    Dim wsCopySh3 As Worksheet
    Dim wsPasteSh4 As Worksheet
    Set wsCopySh3 = Sheets("Sheet3")
    Set wsPasteSh4 = Sheets("Sheet4")
    Dim lastRowSh4 As Long
    lastRowSh4 = ThisWorkbook.Sheets("Sheet4").Cells(Rows.Count, 3).End(xlUp).Row + 1
    Dim M As Long
    'M = wsCopySh3.Range("c" & Rows.Count).End(xlUp).Row
    M = wsCopySh3.[match(2,1/(c:c<>""))]
    wsCopySh3.Range("c1:f" & M).Copy
    wsPasteSh4.Range("C" & lastRowSh4).PasteSpecial Paste:=xlPasteValues

End Sub
 
Upvote 0
try this,

VBA Code:
Sub Paste_NextRow()

    Dim wsCopySh1 As Worksheet
    Dim wsPasteSh2 As Worksheet
    Set wsCopySh1 = Sheets("Sheet1")
    Set wsPasteSh2 = Sheets("Sheet2")
    Dim lastRowSh2 As Long
    lastRowSh2 = ThisWorkbook.Sheets("Sheet2").Cells(Rows.Count, 3).End(xlUp).Row + 1
    Dim N As Long
    'N = wsCopySh1.Range("c" & Rows.Count).End(xlUp).Row
    N = wsCopySh1.[match(2,1/(c:c<>""))]
    wsCopySh1.Range("c1:f" & N).Copy
    wsPasteSh2.Range("C" & lastRowSh2).PasteSpecial Paste:=xlPasteValues
   
    '---------------------------------------
   
    Dim wsCopySh3 As Worksheet
    Dim wsPasteSh4 As Worksheet
    Set wsCopySh3 = Sheets("Sheet3")
    Set wsPasteSh4 = Sheets("Sheet4")
    Dim lastRowSh4 As Long
    lastRowSh4 = ThisWorkbook.Sheets("Sheet4").Cells(Rows.Count, 3).End(xlUp).Row + 1
    Dim M As Long
    'M = wsCopySh3.Range("c" & Rows.Count).End(xlUp).Row
    M = wsCopySh3.[match(2,1/(c:c<>""))]
    wsCopySh3.Range("c1:f" & M).Copy
    wsPasteSh4.Range("C" & lastRowSh4).PasteSpecial Paste:=xlPasteValues

End Sub

Great stuff, thanks alot ,appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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