Copy & paste through a selection

AlexVLZ

New Member
Joined
Dec 28, 2018
Messages
10
Hello all,

First post here!

I am leaning VBA through trial and error, and I need some guidance.

Requirements:


  • Tab A (input): a fix list of countries of 4 (Column A: Spain, UK, USA, Italy)
  • Tab B (input): a variable table of data.
  • Tab C (output): Combine data from Tab A and B. I need to have a table of data (column B) for each country (column A). The code will need to do this for each country in Tab A.

I can manage to copy&paste the data correctly for Spain, but I cannot get the VBA to select the next country from the Tab A list...take it to Tab C and then paste the table (Table from Tab B) next to it.... and so on

MANY THANKS FOR THE HELP!

Alex
 
Re: Desperate noob: Copy&paste through a selection

Does the col B on the output sheet come from col B on sheet "B"?
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Re: Desperate noob: Copy&paste through a selection

The data in Column B comes from Column A on Sheet B.
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

In that case try
Code:
Sub AlexVLZ()
   Dim RngB As Range, Cl As Range
   
   With Sheets("B")
      Set RngB = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
   End With
   RngB.Copy Sheets("C").Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(RngB.Count * 4)
   With Sheets("A")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Cl.Copy Sheets("C").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1 * RngB.Count)
      Next Cl
   End With
End Sub
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

DONE!!! OUTSTANDING!!!:rofl:

With only a couple of adjustments, it now does what I want. And far more efficient than my code.

I will now review the "RESIZE" bit you added - I was unfamiliar with that command.

thanks you very much! May you ride to Vanlhalla peacefully!


Code:
Sub AlexVLZ()
   Dim RngB As Range, Cl As Range
   
   With Sheets("Datos")
      Set RngB = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
   End With
   RngB.Copy Sheets("Resultado").Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(RngB.Count * 5)
   With Sheets("País")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Cl.Copy Sheets("Resultado").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1 * RngB.Count)
      Next Cl
   End With
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

You're welcome & thanks for the feedback
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

hi! sorry for coming up again...

Doubt, lets say the second tab "Details", contains data from cells from A to D. How could i change it to accomodate this?

thanks!

Alex
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

Which tab are you referring to when you say tab "Details", also in what way do you want to "accommodate it"
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

Yes. The Details tab.

Your code takes a column A from the "Details" tab to paste it in column B in the "Results" tab. But can i amend the code in case we need to extract more columns from the "Details" tab, lets say that this tab has a column range from "A to D".
 
Upvote 0
Re: Desperate noob: Copy&paste through a selection

Try
Code:
Sub AlexVLZ()
   Dim RngB As Range, Cl As Range
   
   With Sheets("Datos")
      Set RngB = .Range("A1").CurrentRegion
   End With
   RngB.Copy Sheets("Resultado").Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(RngB.Rows.Count * 5)
   With Sheets("País")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Cl.Copy Sheets("Resultado").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1 * RngB.Rows.Count)
      Next Cl
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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