programatically selecting columns to import text into

S

ScottM

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
 
G

Gord Dibben

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
 
S

ScottM

Thanks for the feedback.

Scott


Gord Dibben said:
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
 
Top