VBA copy/Paste various scenarios macro

mmelels

New Member
Joined
Sep 19, 2014
Messages
2
I am writing some VBA which copies results in a column and pastes them in another column. The problem is that there are 5 different scenarios that I want to do this for so that I can compare each one and in order to change the scenario I need to change an Input cell (C2) to a number 1-5. I have written a code to do this but it is pretty long winded and if want another scneario added then I will need to go in and add some more code. I was wondering if there was a quicker way than what I have done already (see below for my code)


Worksheets("XXX").Range("C2") = 1

Worksheets("XXX").Range("B4:B34").Copy
Worksheets("XXX").Range("D4:D25").PasteSpecial xlPasteValues

Worksheets("XXX").Range("C2") = 2

Worksheets("XXX").Range("B4:B34").Copy
Worksheets("XXX").Range("E4:E25").PasteSpecial xlPasteValues

Worksheets("XXX").Range("C2") = 3

Worksheets("XXX").Range("B4:B34").Copy
Worksheets("XXX").Range("F4:F25").PasteSpecial xlPasteValues

any ideas?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hello & welcome
If the column to paste in is always 3 bigger than the value in C2, how about something like this?
Code:
    Dim Col2Use As Integer

With Worksheets("XXX")
    Col2Use = .Range("C2") + 3

    .Range("B4:B34").Copy
    .Range(.Cells(4, Col2Use), .Cells(25, Col2Use)).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
End With
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,037
Members
449,062
Latest member
mike575

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