Solved

Could I programatically add columns in excell?

Posted on 2011-09-06
5
246 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

895 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

15 Experts available now in Live!

Get 1:1 Help Now