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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating an If statement with value contents of cells

Status
Not open for further replies.
Jul 9, 2007
24
0
0
CA
Hello,
I want to modify the following slightly so that intLineCount variables are not specified number values, but rather are numbers taken from the contents of a column of cells within a specific Excel workbook sheet. (The number of values (non-blank rows) in the column will be different each time the program is run).

How can I code for this, including the 'or' statements? (Do I need the 'or' statements still?)

Thank you,
Any help or suggestions is appreciated.

Marie

p.s. To set the scene a little more, a large number of text files exist already. A new text file has been created and has values parsed from old text files and then written to the new file, line by line. The new text file will have columns which are tab-separated, but the number of columns will depend on the number of rows in the Excel file.


Code:
intLineCount = 1

While Not (ObjUFile.AtEndOfStream Or ObjVFile.AtEndOfStream)
    strLineU = ObjUFile.readLine ' first line indicates how many columns there are
    strLineV = ObjVFile.readLine ' first line indicates how many columns there are
    
    If (intLineCount = 45264 Or intLineCount = 45265) Then
        u = CDbl(Trim(strLineU))
        v = CDbl(Trim(strLineV))
        mag = Sqr(u * u + v * v)
        
        strTSLine = strTSLine & vbTab & mag     ' Adds magnitude component to timestamp row, separated by tab from previous entry
    End If
    
    intLineCount = intLineCount + 1
    
Wend
 
You can specify the value of a particular cell in the if statement:
If (intLineCount = sheets([red]i[/red]).cells([red]j[/red],[red]k[/red]) Or intLineCount = sheets([red]l[/red]).cells([red]m[/red],[red]n[/red]))
where i,l are the worksheet numbers and j,m are the row numbers and k,n are the column numbers.

Are you asking how to set up a loop to go through the spreadsheet(s) and find the right values? To answer that you'd have to specify some kind of validity criteria.

_________________
Bob Rashkin
 
Thanks, Bob. Yes, this is the right idea, except the number of cells is going to vary, so I would like somehow to say:

this cell OR this cell OR this cell... until the end of the occupied rows in this column

I was thinking I would have to populate an array, and started to play around with this without such great luck so far.

Any ideas?

Marie
 
Then I guess you don't have to use Or. Why not something like:
Code:
for each c in sheets(x).columns(y).cells
  if c.value=intLineCount then
     <[red]your stuff[/red]>
     exit for 'optional
  end if
next
if a cell is empty, it won't equal intLineCount.

_________________
Bob Rashkin
 
I tried this, but ... well, one hour later... program was still running but no results. Not sure why: could it have been too time-intensive of a loop?
 
I guess it's time to post your code.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top