Copy a range, paste to another sheet, go to the next column

Ghostmyst

New Member
Joined
Jun 9, 2007
Messages
4
Hello,
I am very new to VBA, I was wondering if anyone can help me with this issue I have.

I want to copy a range (A2:A6) from sheet1 and paste it to a sheet in which the name of it is the same as A1 or sheet1. I want the macro to come back to sheet 1 and repeats on to the next column until it hits a blank cell in row1.

Thanks in advance,
Evelyn
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,

This do anything like what you want?

Code:
Sub Copy_Stuff()

Dim myRange As Range, mySheet As String

Application.ScreenUpdating = False

For Each myRange In Sheets("Sheet1").Range([A1], [A1].End(xlToRight))

    If myRange.Value = "" Then Exit Sub

    mySheet = myRange.Value

    Range(myRange.Offset(1, 0), myRange.Offset(5, 0)).Copy

    Sheets(mySheet).Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False

Next myRange

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Change the destination range as required.

Dom
 
Upvote 0
Thank you!

Just one more question, my range might varies from month to month, so it might not be (A2:A6), it might be (A2:A31). Is there a way to do that?

Thank you so much,
Evelyn
 
Upvote 0
Evelyn,

You can add below code in Dom's code.

Application.ScreenUpdating = False
lastRow = range("A65536").end(xlup).row

For Each myRange In Sheets("Sheet1").Range([A1], [A1].End(xlToRight))

If myRange.Value = "" Then Exit Sub

mySheet = myRange.Value

Range(myRange.Offset(1, 0), myRange.Offset(lastRow-1, 0)).Copy
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

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