ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   programatically selecting columns to import text into (https://www.excelbanter.com/excel-discussion-misc-queries/57172-programatically-selecting-columns-import-text-into.html)

ScottM

programatically selecting columns to import text into
 
Hi,

I am writing a macro to import multiple text files into a spreadsheet. The
only part I haven't figured out is how to step sideways, i.e the first text
file should use A1 as its origin, the second file C1, the third E1 and so
on.

Range(A1).Select
Range(C1).Select
Range(E1).Select


/Scott



Gord Dibben

programatically selecting columns to import text into
 
Scott

Use Offset(rownum, columnnum) to move the activecell.

ActiveCell.Offset(0, 2).Select

Rarely necessary to select anything.

Example........Instead of

Dim actSht As Worksheet
Set actSht = ActiveSheet
Worksheets("Sheet2").Activate
Range("A1:J10").Select
Selection.Copy
actSht.Activate
Range("K43").Select
ActiveSheet.Paste

use

Worksheets("Sheet2").Range("A1:J10").Copy _
Destination:=ActiveSheet.Range("K43")


Gord Dibben Excel MVP

On Thu, 24 Nov 2005 15:19:48 -0500, "ScottM"
wrote:

Hi,

I am writing a macro to import multiple text files into a spreadsheet. The
only part I haven't figured out is how to step sideways, i.e the first text
file should use A1 as its origin, the second file C1, the third E1 and so
on.

Range(A1).Select
Range(C1).Select
Range(E1).Select


/Scott



ScottM

programatically selecting columns to import text into
 
Thanks for the feedback.

Scott


"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Scott

Use Offset(rownum, columnnum) to move the activecell.

ActiveCell.Offset(0, 2).Select

Rarely necessary to select anything.

Example........Instead of

Dim actSht As Worksheet
Set actSht = ActiveSheet
Worksheets("Sheet2").Activate
Range("A1:J10").Select
Selection.Copy
actSht.Activate
Range("K43").Select
ActiveSheet.Paste

use

Worksheets("Sheet2").Range("A1:J10").Copy _
Destination:=ActiveSheet.Range("K43")


Gord Dibben Excel MVP

On Thu, 24 Nov 2005 15:19:48 -0500, "ScottM"
wrote:

Hi,

I am writing a macro to import multiple text files into a spreadsheet. The
only part I haven't figured out is how to step sideways, i.e the first
text
file should use A1 as its origin, the second file C1, the third E1 and so
on.

Range(A1).Select
Range(C1).Select
Range(E1).Select


/Scott






All times are GMT +1. The time now is 07:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com