View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H. Mike H. is offline
external usenet poster
 
Posts: 471
Default Importing Data into an Excel sheet-template

This should work:

Option Explicit
Option Base 1

Sub SetupNewSheet()
Dim FF As Long
Dim X As Double
Dim Y As Double
Dim L As String
Dim Z As Double
Dim DataArray(5000, 10) As Variant
Dim Nbr As Integer
Dim StartRow As Double
Dim StartCol As Double
Sheets("hasdata").Select

StartRow = 1 'Starting Row
StartCol = 4 'Starting Column
X = StartRow
Do While True
If Cells(X, StartCol).Value = Empty Then Exit Do 'assume col 1 always
has data
For Z = 1 To 10
Cells(X, StartCol + Z - 1).Value = Empty 'blanks out all previous data
Next
X = X + 1
Loop
'now open your new data file


FF = FreeFile()
Open "c:\temp\thefile.txt" For Input As #FF '<--Change File name as
required.

Do While Not EOF(FF)
Line Input #FF, L
Nbr = Nbr + 1
For Y = 1 To 9
Let DataArray(Nbr, Y) = Left(L, InStr(L, ",") - 1)
Let L = Right(L, Len(L) - Len(DataArray(Nbr, 1)) - 1)
Next
Let DataArray(Nbr, 10) = L

Loop
Close #FF

For X = 1 To Nbr
For Y = 1 To 10
Cells(StartRow + X - 1, StartCol + Y - 1).Value = DataArray(X, Y)
Next
Next



End Sub