Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Go Back  Xtreme Visual Basic Talk > > > Copy entire column and paste into new workbook using for loop


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2014, 03:44 AM
bellaelysium bellaelysium is offline
Regular
 
Join Date: Jun 2008
Posts: 91
Unhappy Copy entire column and paste into new workbook using for loop


Hi,

I have write up the following code:

Code:
        'select column one by one using for loop (D to AG column) to paste into different workbooks
        Dim rang1, copyrange, cellStart As Excel.Range
        Dim colNum As Integer
        Dim i As Integer

        Dim oApp As New Excel.Application
        Dim oWB As Excel.Workbook = oApp.Workbooks.Add()

        'make Excel visble and give user control
        oApp.Visible = True
        oApp.UserControl = True

        'Get the first worksheet in the book.
        Dim ws1 As Excel.Worksheet


        'Create another Workbook.
        'Dim excelWorkbook1 As Excel.Workbook = New Excel.Workbook()

        colNum = TextBox1.Text + 3

        For i = 4 To colNum

            rang1 = WSheet.Cells(WSheet.Rows.Count, i).end(Excel.XlDirection.xlUp)
            cellStart = WSheet.Cells(1, i)
            WSheet.Columns(i).copy()


            ws1 = oWB.Sheets("Sheet1")
            ' ws1 = oWB.ActiveSheet
            ws1.Paste()

        Next
What I am trying to do is to copy D column , put into new workbook. E column into new workbook. But for now, I am trying to put different column into worksheets of same workbook before trying to figure out how to put in multiple workbooks.

However, when a number input into textbox is e.g. "2", it will only copy column E into a new workbook and stop there.

How do I loop through column D to a specific column (as stated by user input in textbox) and paste the column data into new workbook each time?

I hope there is someone who can help me in the right direction.

Thanks

Last edited by bellaelysium; 02-06-2014 at 03:12 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
 
Copy entire column and paste into new workbook using for loop
Copy entire column and paste into new workbook using for loop
 
-->