Paste selected range of cells in other worksheets first free cell

Jani_Jani

New Member
Joined
May 13, 2018
Messages
4
Hello,
I know there are few similar threads and I've tried a few advised codes, but it still doesn't work at all. I've also tried to change them a bit to match my purpose but I failed (call me dummy, but I've spend the whole weekend working on this thing and my brain fails me).

What I need is a VBA code which would let me:
  1. From sheet "Africa" copy cells from between D1 and K1 down to the last filled row.
  2. Paste them in A1 of sheet "World"
  3. From sheet "Asia" copy the cells from between D2 and K2 down to the last filled row.
  4. Paste them in the first empty cell of sheet "World" under the data copied form "Africa"

Anything which works is fine but the simpler the better as my thinker is fried already :help:...
Thank you.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about
Code:
Sub CopyShts()
   Dim Ws As Worksheet
   
   Set Ws = Sheets("World")
   With Sheets("Africa")
      .Range("D1", .Range("K" & Rows.Count).End(xlUp)).Copy Ws.Range("A1")
   End With
   With Sheets("Asia")
      .Range("D2", .Range("K" & Rows.Count).End(xlUp)).Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
   End With
End Sub
 
Upvote 0
How about
Code:
Sub CopyShts()
   Dim Ws As Worksheet
   
   Set Ws = Sheets("World")
   With Sheets("Africa")
      .Range("D1", .Range("K" & Rows.Count).End(xlUp)).Copy Ws.Range("A1")
   End With
   With Sheets("Asia")
      .Range("D2", .Range("K" & Rows.Count).End(xlUp)).Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
   End With
End Sub
It's... It's... It's ALIVE :grin:!
Thank you so much!
VA01008lg.425.jpg

I've adapted to code to work also in other similar cases I have a problem with one instance though where I have to paste the values (as everywhere else the same columns from different sheets one under the other) but with source with Paste:=xlPasteAllUsingSourceTheme, not sure in which place this command should go as to not spoil everything...
 
Upvote 0
Try
Code:
Sub CopyShts()
   Dim Ws As Worksheet
   
   Set Ws = Sheets("week")
   With Sheets("pcode")
      .Range("D1", .Range("K" & Rows.Count).End(xlUp)).Copy
      Ws.Range("A1").PasteSpecial xlPasteValues
      Ws.Range("A1").PasteSpecial xlPasteFormats
   End With
   With Sheets("Asia")
      .Range("D2", .Range("K" & Rows.Count).End(xlUp)).Copy
      Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
      Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteFormats
   End With
End Sub
 
Upvote 0
Try
Code:
Sub CopyShts()
   Dim Ws As Worksheet
   
   Set Ws = Sheets("week")
   With Sheets("pcode")
      .Range("D1", .Range("K" & Rows.Count).End(xlUp)).Copy
      Ws.Range("A1").PasteSpecial xlPasteValues
      Ws.Range("A1").PasteSpecial xlPasteFormats
   End With
   With Sheets("Asia")
      .Range("D2", .Range("K" & Rows.Count).End(xlUp)).Copy
      Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
      Ws.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteFormats
   End With
End Sub

Today you've became someones hero :)

giphy.gif
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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