?
Solved

skip field on import

Posted on 2003-03-29
4
Medium Priority
?
151 Views
Last Modified: 2010-05-01
i have the following code but i want to not import the first field and the 5th field
is this possible?

Dim fso As New FileSystemObject
  Dim ts As TextStream
  Dim rowNo As Integer
  Dim i As Integer
  Dim xlRow() As String
  Dim xla As Excel.Application
  Dim xlw As Excel.Workbook
  Dim xls As Excel.Worksheet
 
  Set xla = CreateObject("Excel.Application")
  Set xlw = xla.Workbooks.Add
  Set xls = xlw.Sheets("Sheet1")
  rowNo = 1
  xla.Visible = False

  Set ts = fso.OpenTextFile("c:\test\file.txt")
  Do While ts.AtEndOfStream <> True
      xlRow = Split(ts.ReadLine, ",", -1, vbTextCompare)
      For i = 0 To UBound(xlRow)
          xlRow(i) = Replace(xlRow(i), Chr(34), "")
          xls.Cells(rowNo, i + 1) = xlRow(i)
      Next i%
      rowNo = rowNo + 1
  Loop
  ts.Close
 
  xlw.SaveAs ("c:\test\file.xls")
  xla.Quit
  Set xla = Nothing
0
Comment
Question by:Marcusw
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
jyokum earned 1000 total points
ID: 8232658
For i = 0 To UBound(xlRow)
   if not i = 0 and not i = 4 then
       xlRow(i) = Replace(xlRow(i), Chr(34), "")
       xls.Cells(rowNo, i + 1) = xlRow(i)
   end if
Next i%
0
 

Expert Comment

by:CleanupPing
ID: 8531345
Hi Marcusw,
This old question (QID 20567693) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 12

Expert Comment

by:jyokum
ID: 9301540
Marcusw,
This has been open 161 days and there hasn't been a comment added in 114 days.
Please select a comment as the solution or give us an update.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440691
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept jyokum's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question