Getting a weird result on this one sheet in Excel

B

Brent White

I am trying to extract data from several Excel spreadsheets using the
Excel object in VBA (Access 2000, specifically). However, this one
spreadsheet is giving me a headache.

This is the code:

Sub ProcessSpreadsheet(xlbk As Excel.Workbook)
Dim xlsheet As Excel.Worksheet
Dim RSOUT As Recordset
Dim style As String
Dim color As String
Dim ONHAND As Long
Dim i As Long
Set RSOUT = CurrentDb.OpenRecordset("tblCutOrders")
RSOUT.Index = "PrimaryKey"
For Each xlsheet In xlbk.Worksheets
With xlsheet
'If xlsheet.Name = "VEGAS GOLD" And .Range("G1") = "95" Then
Stop
ONHAND = 0
If .Name <> "TOTAL" Then
color = .Name
style = .Range("G1")
i = 4
Do Until xlsheet.Range("D" & i) = "TOTAL"
If InStr(1, .Range("D" & i), "INVENTORY") > 0 Or
InStr(1, .Range("D" & i), "ADJUST") > 0 Or Trim(.Range("D" & i)) = ""
Or InStr(1, .Range("D" & i), "RECEIVED") > 0 Or InStr(1, .Range("D" &
i), "DEFECT") > 0 Then
Debug.Print "Not a cut"
ONHAND = ONHAND + Val(xlsheet.Range("e" & i))
ElseIf InStr(1, xlsheet.Range("D" & i), "ORDER") > 0
Then
CurrentDb.Execute "INSERT INTO
tblFabricOrders(STYLE,COLOR,FabricOrder,Yards) VALUES('" & style &
"','" & color & "','" & .Range("D" & i) & "'," & .Range("E" & i) & ")"
ONHAND = ONHAND
Else
RSOUT.Seek "=", style, color, xlsheet.Range("D" &
i)
If Not RSOUT.NoMatch Then
RSOUT.Edit
RSOUT!CUTYARDS = -1 * Val(xlsheet.Range("E"
& i))
RSOUT.Update
Else
RSOUT.AddNew
RSOUT!style = style
RSOUT!color = color
RSOUT!CUTORDERNUMBER = xlsheet.Range("D" &
i)
RSOUT!CUTYARDS = -1 * Val(xlsheet.Range("E"
& i))
RSOUT.Update
End If
ONHAND = ONHAND + Val(xlsheet.Range("e" & i))
End If
i = i + 1
DoEvents
Loop
CurrentDb.Execute "INSERT INTO tblInventory(STYLE, COLOR,
Yards) VALUES('" & style & "','" & color & "'," & ONHAND & ")"
End If
End With
Next

End Sub


I call ProcessSpreadsheet with xlbk defined as an Excel Workbook. When
I get to the part where it looks for values in xlsheet.range("E" & i)
or .range("E" & i) (I've tried it both ways), the value for
..range("E4") is blank on this one sheet, but when I go to the sheet,
cell E4 is certainly not blank and has a numeric value in it.

I've recreated the sheet, cut and pasted values into it, to no avail.
Other sheets seem to work just fine, according to the person who was
looking at the data with me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top