View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Recognise value not formula

You could look for both constants and formulas in that range:

Add a couple of Dim's at the top:

Dim rng1F As Range
Dim rng1C As Range

Then plop this portion in the middle (and delete the corresponding portion):

With ActiveSheet
Set rng1 = Nothing
Set rng1C = Nothing
Set rng1F = Nothing
On Error Resume Next
Set rng1C = .Range("R74:R1000"). _
SpecialCells(xlConstants, xlNumbers)
Set rng1F = .Range("r74:r1000"). _
SpecialCells(xlFormulas, xlNumbers)
On Error GoTo 0
If rng1C Is Nothing Then
Set rng1 = rng1F
Else
If rng1F Is Nothing Then
Set rng1 = rng1C
Else
Set rng1 = Union(rng1F, rng1C)
End If
End If
If rng1 Is Nothing Then
MsgBox "No Quantities in InvSter"
Exit Sub
End If
End With



Pat wrote:

When the following code is executed it will behave as it should. The problem
arises when a value in ("R74:R1000") is returned from a formula. Does anyone
know how can I get around this problem?

Thanks in advance if you can help.
Pat

The code as follows:

Private Sub BTStock_Click()
Dim sProd As String
Dim icol As Long
Dim Rng As Range
Dim rng1 As Range
Dim rng2 As Range, Target As Range
Dim res As Variant
Set Rng = Worksheets("ControlCentre").Range("AL30")
res = Application.Match(ActiveSheet. _
Range("R26").Value, Rng, 0)
If Not IsError(res) Then
icol = Rng(res).Column
Else
MsgBox "InvSter not matched"
Exit Sub
End If
With ActiveSheet
Set rng1 = Nothing
On Error Resume Next
Set rng1 = .Range("R74:R1000"). _
SpecialCells(xlConstants, xlNumbers)
On Error GoTo 0
If rng1 Is Nothing Then
MsgBox "No Quantities in InvSter"
Exit Sub
End If
End With

For Each Target In rng1
sProd = Target.Parent.Cells(Target.Row, 17)

res = Application.Match(sProd, _
Worksheets("ControlCentre").Range("C77:C1000"), 0)
If Not IsError(res) Then
With Worksheets("ControlCentre")
If IsNumeric(Target.Value) Then
Set rng2 = .Cells(res + 76, icol)
rng2.Value = rng2.Value + Target.Value
End If
End With
Else
MsgBox "Product Not found: " & sProd
End If
Next

End Sub


--

Dave Peterson