Brady,
As Ian said you can't use IF like that, in fact my XL 97 highlighted that
line in red indicating a syntax error
I altered your code by simply removing the second IF and it worked for me.
It is, however, case sensitive and so, unlike a worksheet function it would
not find
"Not Inventory" so I wrapped it in UCase and, in case the user adds a
trailing space, I added a Trim as well:
'Populate Pull/Buy Cells
Needed = Cells(RowNum, ColN5) - Cells(RowNum, ColN4)
If Needed < Cells(RowNum, ColN6) * 0.9 _
Or UCase(Trim(Cells(RowNumMin, ColPN).Value)) = "NOT INVENTORY"
Then
Cells(RowNum, ColN7).Value = "Buy"
Else
Cells(RowNum, ColN7).Value = "Pull"
End If
Note that neither the UCase nor the Trim changes the entry in the worksheet.
Personally when I was at work, (I retired on Monday), I often unsed event
code to change, say, a user entry of "NI" into "Not Inventory" to ensure
that users were not making errors in entering data into the cell when I was
going to searching for an exact entry.
--
HTH
Sandy
Retired from Work
But hopefully not from Life
with @tiscali.co.uk
"Brady" wrote in message
oups.com...
I am trying to populate a cell via vba based on the value of another
cell(s).
For example, let's say:
A1 contains a current inventory level of a part (say 12)
B1 contains a minimum required level in inventory (say 10)
C1 contains how many of a certain part I need (say 3)
I have code that determines if A1-C1 is less than B1. If so, then D1 is
populated with "Buy". If not, then the cell is populated with "Pull".
My code works fine for this. So far so good.
Here is the problem:
I want to be able to flag any part labeled as "not inventory" in cell
E1 as "Buy" as there is no data for the "in stock" or "minimum stock"
values.
So, here is my code:
NOTE!!! I am using variables to step through the rows 1 by 1. So, the
code you see before you is part of a larger For/Next loop.
'Populate Pull/Buy Cells
Needed = Cells(RowNum, ColN5) - Cells(RowNum, ColN4)
If Needed < Cells(RowNum, ColN6) * 0.9 _
Or If Cells(RowNumMin, ColPN).Value = "not inventory" Then
Cells(RowNum, ColN7).Value = "Buy"
Else
Cells(RowNum, ColN7).Value = "Pull"
End If
The problem:
When I added this line -- Or If Cells(RowNumMin, ColPN).Value = "not
inventory"
The portion of code that fills in "Buy" stops working. It simply no
longer puts the value of "Buy" in ANY cell.
If I take out the "Or..." code, it works fine.
The part numbers are values that look like this 555-11-222 via a custom
format. The "actual" value in the cell is 55511222. And of course there
are several with the text "not inventory".
If I change all of the "not inventory" cells to something like 99911222
and then change my "Or..." code to this:
Or If Left(Cells(RowNumMin, ColPN).Value,1) < 5
Then the code works fine and I get "Buy" in the appropriate cells.
Why can't my original code "see" the "not inventory" in the cells?????
I should also note that I put in a message box show what the code
thought was in Cells(RowNumMin, ColPN) and it completely skips "not
inventory" cells!