Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a macro to import from another spreadsheet


I have a spreadsheet which needs to have some data extracted from it
the data manipulated and then the whole thing exported as a text file.

I have no problem with the second and third part of this but I a
struggling with the first part:

How does one use a macro to import columns from another spreadsheet
The problem is I don't want all of the columns, only some and no
necessarily in the order in which they are in the original sheet
something like this. I will write this in English so that I hope
explain what I want:

Dim startRow as integer
StartRow = 6
For rows = StartRow to 65536

If Column A is empty then finish

Move to First blank row of output sheet

Import Row X, Column A from Input Sheet
Move to Next Column
Import Row X, Column D from Input Sheet
Move to Next Column
Import Row X, Column B from input sheet
(etc....)

Repeat until all rows are done

The problem is I don't know how to import data from one workbook t
another when you don't know how many rows there are

--
zaphod200
-----------------------------------------------------------------------
zaphod2003's Profile: http://www.excelforum.com/member.php...fo&userid=3436
View this thread: http://www.excelforum.com/showthread.php?threadid=54139

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using a macro to import from another spreadsheet

etc kind of leaves a lot to guessing, but....

And you'll be getting data from worksheets. I used fWks as the From Worksheet
and tWks as the To Worksheet, so you'll have both of those workbooks open and
you'll need to change the code to point at the correct worksheet in each of
those workbooks:

Option Explicit
Sub testme01()

Dim fWks As Worksheet
Dim tWks As Worksheet
Dim iRow As Long
Dim LastRow As Long
Dim NextRow As Long

Set fWks = Workbooks("book2.xls").Worksheets("sheet2")
Set tWks = Workbooks("book1.xls").Worksheets("sheet1")

With tWks
'find last used row in column A and add 1
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With

With fWks
'find the last used row in column A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = 6 To LastRow
tWks.Cells(NextRow, "A").Value = .Cells(iRow, "A").Value
tWks.Cells(NextRow, "B").Value = .Cells(iRow, "D").Value
tWks.Cells(NextRow, "C").Value = .Cells(iRow, "B").Value
'keep going
'get ready to import to the next row
NextRow = NextRow + 1
Next iRow
End With

End Sub



zaphod2003 wrote:

I have a spreadsheet which needs to have some data extracted from it,
the data manipulated and then the whole thing exported as a text file.

I have no problem with the second and third part of this but I am
struggling with the first part:

How does one use a macro to import columns from another spreadsheet.
The problem is I don't want all of the columns, only some and not
necessarily in the order in which they are in the original sheet,
something like this. I will write this in English so that I hope I
explain what I want:

Dim startRow as integer
StartRow = 6
For rows = StartRow to 65536

If Column A is empty then finish

Move to First blank row of output sheet

Import Row X, Column A from Input Sheet
Move to Next Column
Import Row X, Column D from Input Sheet
Move to Next Column
Import Row X, Column B from input sheet
(etc....)

Repeat until all rows are done

The problem is I don't know how to import data from one workbook to
another when you don't know how many rows there are.

--
zaphod2003
------------------------------------------------------------------------
zaphod2003's Profile: http://www.excelforum.com/member.php...o&userid=34362
View this thread: http://www.excelforum.com/showthread...hreadid=541399


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import from spreadsheet Kjeldc Excel Programming 4 February 7th 10 02:43 AM
Macro to import & update rows in spreadsheet based on Ref ID. Harry Seymour[_2_] Excel Discussion (Misc queries) 0 June 9th 08 04:05 PM
Import an excel spreadsheet in ASP.NET Uma Muthu Excel Programming 0 April 7th 06 09:49 PM
Import from spreadsheet sebastienm Excel Programming 0 March 26th 06 11:44 PM
Import a spreadsheet Spencer Hutton[_3_] Excel Programming 3 December 21st 04 02:28 PM


All times are GMT +1. The time now is 04:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"