+ Reply to Thread
Results 1 to 2 of 2

Whats Wrong With My Code Please?

  1. #1
    Registered User
    Join Date
    10-23-2006
    Posts
    84

    Unhappy Whats Wrong With My Code Please?

    Dim VatRate As Single

    Private Sub Vat()

    If opt0 Then
    VatRate = 0
    ElseIf opt5 Then
    VatRate = 0.05
    ElseIf opt18 Then
    VatRate = 0.18
    End If

    End Sub

    Private Sub SaveRow()
    Cells(Cr, 1).Value = txtInvDate.Text
    Cells(Cr, 2).Value = txtInvNum.Text
    Cells(Cr, 3).Value = txtInvSup.Text
    Cells(Cr, 4).Value = txtInvGoods.Text
    Cells(Cr, 5).Value = txtInvVal.Text
    If opt0 = True Then
    Cells(Cr, 6).Value = VatRate
    Cells(Cr, 6).Value = VatRate * Cells(Cr, 5).Value
    Cells(Cr, 9).Value = Cells(Cr, 5).Value + Cells(Cr, 6).Value
    ElseIf opt5 = True Then
    Cells(Cr, 7).Value = VatRate
    Cells(Cr, 7).Value = VatRate * Cells(Cr, 5).Value
    Cells(Cr, 9).Value = Cells(Cr, 5).Value + Cells(Cr, 7).Value
    ElseIf opt18 = True Then
    Cells(Cr, 8).Value = VatRate
    Cells(Cr, 8).Value = VatRate * Cells(Cr, 5).Value
    Cells(Cr, 9).Value = Cells(Cr, 5).Value + Cells(Cr, 8).Value
    End If
    End Sub

    opt0, opt5 and opt18 are 3 option buttons
    no matter which one I check the value goes in as 0

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon GogsJames

    The problem appears to be that option boxes have lots of properties that need to be specified when calling information from them. The property for checking whether it's been clicked is .Value as a boolean value, so your code needs to be amended thus :

    If opt0.Value=1 Then
    VatRate = 0

    1 (or TRUE) =Clicked box
    0 (or FALSE) = Non-clicked box

    HTH

    DominicB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1