Hi, markhughes!
I downloaded your file and I notice this:
a) In userform Selection, CommandButton1 click event (the above code), "c" is a one-cell range that varies from B5 thru B100 and G5 thru G100, that's to say the loop is performed 192 times, but:
- you're checking its value against a two-cell range value (B6,F6), for which -even if they have individual values in B6 and F6 and Excel doesn't raise an error- the text property is null: just debug it and check for the value
- despite of that, the value to be subtracted when the condition is true (what it won't happen accordingly to previous paragraph) is related to a two-cell range (C6,G7) in my humble opinion should be (C6,G6)
b) To reduce search loops thru empty cells I would change the loop structure to something like this, if there are unique entries in range 5:100:
-----
[pre]
Code:
If Len(c.Text) = 0 Then Exit For
If Condition Then
Action
Exit For
End If
-----
or, if there are duplicate entries in range 5:100:
-----
If Len(c.Text) = 0 Then Exit For
If Condition Then
Action
End If
[/pre]
-----
c) If what you intended to do is checking "c" value against B column and then after G column, you should use two nested If structures, as a two-cells range text property returns null, even both individual cells text property are not empty
d) I would add an empty column before E column in sheet Selection, so as to maintain the same structure and offsets that in sheet Stock: in this way, you would compare/use columns B against columns B and columns G against columns G, which I think is clearer than B vs. B and F vs. G.
Summary: you're right, the above code doesn't work, let us know what was the intended action and we'll try to help you fixing it.
Regards!