Hi
changing it a little bit to the following it runs without an error for
me
Sub TestRound2()
Dim ws As Worksheet, R As Range, C As Range
Dim qty As Single, rate As Single, Data As Single
With ActiveSheet
'.Unprotect
Set C = .Range("D2")
Data = C.Offset(0, 9).Value
qty = C.Value
rate = C.Offset(0, 2).Value
If Data 0 Then
If Data = 5 Then
C.Offset(0, 4).Value = Round(qty * rate * Data / 100, 2)
ElseIf Data = 17.5 Then
C.Offset(0, 5).Value = Round((qty * rate * Data) / 100, 2)
End If
End If
End With
MsgBox Round(qty * rate * Data / 100, 2)
End Sub
--
Regards
Frank Kabel
Frankfurt, Germany
"Stuart" schrieb im Newsbeitrag
...
Sorry, should have checked that code.
Here's a simpler option:
Active sheet has the following values
D2 = "1.68" F2 = "393.75" M2 = "5"
on it I ran this sub:
Sub TestRound2()
Dim ws As Worksheet, R As Range, C As Range
Dim qty As Single, rate As Single, Data As Single
With ActiveSheet
.Unprotect
Set C = .Range("D2")
C.Offset(0, 9).Value = Data
qty = C.Value
rate = C.Offset(0, 2).Value
If Data 0 Then
If Data = 5 Then
C.Offset(0, 4).Value = Round(qty * rate * Data / 100, 2)
ElseIf Data = "17.50" Then
C.Offset(0, 5).Value = Round((qty * rate * Data) / 100,
2)
End If
End If
End With
End Sub
Regards.
"Frank Kabel" wrote in message
...
Hi
difficult to test as I got at least 3 compiler errors:
- two End Ifs without an opening If
- an undefined label
But looking at the lines:
If Data 0 Then
If Data = "5.00" Then
C.Offset(0, 4).Value = Round(qty * rate * Data / 100, 2)
ElseIf Data = "17.50" Then
C.Offset(0, 5).Value = Round((qty * rate * Data) / 100, 2)
Data is defined as long but you make a string comparison with (If
Data
= "5.00")
Also try to set a breakpoint before these lines and look at the
values
for each variable and check the results
--
Regards
Frank Kabel
Frankfurt, Germany
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.601 / Virus Database: 382 - Release Date: 29/02/2004