Macro to copy range from one worksheet to another into the appropriate month

reece1984

New Member
Joined
May 15, 2012
Messages
18
Hi All,

I've been working on this for while, i'm sure its quite simple for some of you.

The challenge is to have a macro which copies a range from an input worksheet and pastes it onto an "archive" worksheet into the appropriate month's column. The size of the range will be standard.

I expect that this can be done with an offset, which can move along the months on the archive sheet the amount of months that the current month is from the first month on the archive sheet. Or perhaps a lookup?

I've been trying different things in vba but cannot get it to work.

Any help would be really appreciated because this would solve a problem lots of my files.

J
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

Thanks for your reply.

I have progressed a little since my post. Here is my code:

Sub archive1()

Sheets("input").Select
Range("C6:C10").Cut
Sheets("archive").Select
Range("C6:C10").Offset(0, Range("B3")) = ActiveSelection.Paste

End Sub

The part that says ActiveSelection.Paste does not work but it is there to show you what I'm trying to do.

Any ideas?
 
Upvote 0
Do you want to paste your data in Range("B3")? Maybe so:
Code:
Sub archive1()
    Sheets("input").Select
    Range("C6:C10").Copy
    Sheets("archive").Select
    Range("B3").Select
    ActiveSheet.Paste
End Sub
 
Upvote 0
or so:
Code:
Sub archive1()
    Worksheets("archive").Range("C6:C10") = Worksheets("input").Range("B3:B7").Value
End Sub
 
Upvote 0
Sorry, I didnt explain that very well at all but your code really helped.

For the purposes of anybody reading this post.

B3 is a number which is linked to a combo box to signify the current month.

So I wanted to copy a range on "input" worksheet, and then paste it into "archive worksheet" but offset the number of months from january.

The code which now appears to work great is:

Range("C6:C10").Offset(0, Range("B3")) = Worksheets("input").Range("C6:C10").Value

Andrew, Thanks very much.


This thread is now closed.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,349
Members
449,155
Latest member
ravioli44

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