Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript reading out Excel CSV file

Status
Not open for further replies.

steen101

IS-IT--Management
May 7, 2019
1
NL
My script reads out 3 lines (introw 1, 2 and 3). But it only shows the intRow line 2, how can I make the inputbox look for the line in Excel and show it in the message box? Help would be appreciated!

' Read an Excel Spreadsheet
sFNInput="C:\Models.csv"

' User enters value
sInp=Inputbox("Enter Identity text")
If sInp = "" Then WScript.Quit
On Error Resume Next
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open_(sFNInput)
Do Until objExcel.Cells(intRow,1).Value = ""
sID=objExcel.Cells(intRow, 1).Value
sType=objExcel.Cells(intRow, 2).Value
sColor=objExcel.Cells(intRow, 3).Value

Introw = 2

' If user entered value matches (row 2 matches value before comma in row 1)
sResult = InStr(1,sID,sInp,1)
If sResult <> 0 Then

'return row 3
sResult=sGroup

' entered value goes in Field 1 of my application
Field1=sInp

' return value goes in Field2 of my application
Field2= sResult
end if

intRow = Introw + 1
msgbox "productRange: " & sID & " type: " & sType & " colorcode: " & sColor
Loop
objExcel.Quit
 
You never initialize your Introw variable to 1 before the loop.

And without regard to the fact that you increment Introw by 1, you assign Introw to 2 inside your loop???

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top