copying few columns from one worksheet to new worksheet

venkat356

New Member
Joined
Jun 9, 2008
Messages
32
HI,

Am new to this forum.i have one worksheet from which i need to copy only few columns (Ex column A,B, D,G...need not be in sequence.....) to a new sheet.can you please help me to write a macro for this.In addition: Do we need to specify the number of rows in column or is there any way to get data till the end of column automatically.

Thanks in Advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the board..

When A B D G are copied, do they need to be pasted to A B D and G ? or can they go into A B C D ??

If so, you can write this up yourself..Using the Macro Recorder...
Click Tools - Macro - Record New Macro
Give it a name

it will now record your actions.

so hold CTRL key down, highlight the 4 columns - copy
Click Insert - Worksheet
Right click, Paste

now stop recording - Tools - Macro - Stop Recording.


Hope this helps..
 
Upvote 0
Try this

Code:
Sub CopyCols()
Dim cols, LR As Long, ws1 As Worksheet, ws2 As Worksheet
Dim i As Integer, iCol As Integer
cols = Array("A", "B", "D", "G")
Set ws1 = ActiveSheet
Worksheets.Add
Set ws2 = ActiveSheet
iCol = 0
With ws1
    For i = LBound(cols) To UBound(cols)
        iCol = iCol + 1
        LR = .Range(cols(i) & Rows.Count).End(xlUp).Row
        .Range(cols(i) & "1:" & cols(i) & LR).Copy Destination:=ws2.Cells(1, iCol)
    Next i
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0
HI Vog thanks for your qucik help,got the power of Excel

well i need some more robustness in the process,following are my requirements

I have one excel file details.xls.in that i have worksheets named monday,tuesday,wednesday list goes on.now i need the same process which i requested earlier in this post...have to copy few columns from each sheet and to be pasted in a new sheet like monday.xls,tuesday.xls respectively.....This is my first requirement..

and second one i need to generate graphs automatically with the data column A vs B,C,G...list may vary....

i appreciate quick help from this forum,and would like to know about this programming from the scratch,suggest some online resources

Thanks in advance
 
Upvote 0
I'm assuming that the copying and pasting code above works.

The question about charts is a different one. I suggest that you start the macro recorder then create a chart manually. Stop the macro recorder and examine the code. If you need help modifying the recorded code, paste it here but in a new thread because this one originally had nothing to do with charts.

Hint: Include 'chart' in the title - then a chart expert is likely to read it ;)
 
Upvote 0
HI Vog,

The code you gave for copying few columns worked,Thanks a lot.But i need some more help on this

have one excel file details.xls.in that i have worksheets named monday,tuesday,wednesday list goes on.now i need the same process which i requested earlier in this post...have to copy few columns from each sheet and to be pasted in a new sheet like monday.xls,tuesday.xls respectively.....

Please suggest me

Regards
 
Upvote 0
I am unclear.

Do you want to copy from the same columns to each sheet or different columns to each sheet?

Do the sheets monday, tuesday already exist? If so should the pasted data overwrite what is already there?

You need to be a lot more specific.
 
Upvote 0
I need the data from sheet1,sheet2 of a work book with names Monday,tuesday.....to be pasted into a new workbook separately with names Monday.xls,Tuesday.xls
In simple words...monday sheet to monday.xls......
Regards
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

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