Macros that copy certain range to another cell conditionally

burnin2emax

New Member
Joined
Nov 9, 2005
Messages
10
Hi there,

I need help in a macro to perform the following.

The situation is as such :
I have a cell C6 waiting for user input.
I want to create a control button which runs a macro which will copy certain range of cells according to the user input.

For example, when a user keys in "a" at cell C6, when the macro is run, columns(A:D) of Worksheet A are copied to columns(B:E) of Worksheet B.
When a user keys in "b" at cell C6, when the macro is run, columns(E:H) of Worksheet A are copied to columns(B:E) of Worksheet B.

Hope someone can help.

Thanks in advance.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi
paste the code onto sheet module
Code:
Option Compare Text

Private Sub Worksheet_Change(ByVal Target As Range)
Dim txt As String
With Target.Cells(1, 1)
    If .Address(0, 0) <> "C6" Then Exit Sub
    Select Case .Value
        Case "a"
            txt = "A:D"
        Case "b"
            txt = "E:H"
        Case Else
            Exit Sub
    End Select
    Me.Range(txt).Copy Sheets("sheet2").Range("b1")
End With
End Sub
 
Upvote 0
Hi ,

Being the noob that I am, I don't quite grasp what's happening in the code that was given. Perhaps, someone can enlighten me.

As mentioned in earlier post, I want to create a control button which runs a macro which copy certain range of cells according to a user input and copy it into another sheet.

Situation :
If user input "a" into cell C6, when the macro is run, the range(A1:D1) of "worksheet A" are copied onto (A5:D5) of another worksheet, "worksheet B".
If user input "b" into cell C6, when the macro is run, the range(A2:D2) of "worksheet A" are copied onto (A5:D5) of another worksheet, "worksheet B".

Thanks in advance for the help...
 
Upvote 0

Forum statistics

Threads
1,213,528
Messages
6,114,154
Members
448,553
Latest member
slaytonpa

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