Solved

Could I programatically add columns in excell?

Posted on 2011-09-06
5
245 Views
Last Modified: 2012-05-12
Is there  a way to programatically copy and paste calculated columns from an existing worksheet to a newly created worksheet?  I currently do it manually, but would like to be able to just click a button and create the columns to the new worksheet that I receive from a SQL report server..  

Code examples would be helpful.    

thanks
0
Comment
Question by:epicazo
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
hitsdoshi1 earned 250 total points
ID: 36489778
Something like this would do the job.
Sub CopyCol()
    Columns("C:C").Select
    Selection.Copy
    Workbooks.Add
    Columns("C:C").Select
    ActiveSheet.Paste
End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:sdwalker
ID: 36490846
If you're trying to paste the values (and not the formulas), you'll need to to replace the Activesheet.Paste with this.
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
		:=False, Transpose:=False

Open in new window

0
 

Author Comment

by:epicazo
ID: 36588894
I am sorry,   i meant from copy to another newly created excel sheet which is not the same filename
0
 
LVL 9

Expert Comment

by:hitsdoshi1
ID: 36589307
The code I mentioned earlier would copy to another newly created excel sheet only.

Line workbooks.add - creates new excel workbook
0
 

Author Closing Comment

by:epicazo
ID: 36944448
thanks.  sry for the delay
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now