Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Excel macro to get selected colums to a new sheet

Hi,

I want a macro to ask me which all colums i need to copy to a new sheet.
A,C,F and so on.Ant the macro copies all data in the rows to a new sheet.

Regards
Sharath
Avatar of gtgloner
gtgloner
Flag of Canada image

Try this macro in VBA:

Sub copycols()

    Dim colrange As String
    colrange = InputBox("Select column letter to be copied. If there are 2 or more adjacent, type colon inbetween eg. for columns C to G, type C:G")
   

    Columns(colrange).Select
    Selection.Copy
    Sheets.Add
    Columns("A:A").Select
    ActiveSheet.Paste
   
End Sub
Avatar of bsharath

ASKER

Is there a way to give as
A:B:D:G:H
All at the same time.This work make work more easier
After 1 colum it creates a new page and for the 2nd time i rin the script it goes again to a new page
I don't know how this can be done with non-contiguous ranges in a macro. I think you have to take the different sets of columns one at a time when copying them from one sheet to another
Ok then how can i do to copy colums A,C and J
Any help...
Avatar of Wayne Taylor (webtubbs)
Hello bsharath,

When copying the columns to the new sheet, do you wish the data to go in the same column, or just from left to right?

Regards,

Wayne
I want it to copy the full row left and right.
It needs to start from Colum "A"
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I want to copy to A,B,C
bsharath,

Try the macro I posted.

Wayne