+ Reply to Thread
Results 1 to 5 of 5

How to Add the Possibility of Letters into VBA formula

Hybrid View

justinprime How to Add the Possibility of... 11-30-2012, 04:06 PM
JBeaucaire Re: How to Add the... 11-30-2012, 08:53 PM
justinprime Re: How to Add the... 12-01-2012, 12:56 PM
Norie Re: How to Add the... 12-01-2012, 01:12 PM
justinprime Re: How to Add the... 12-05-2012, 12:47 PM
  1. #1
    Registered User
    Join Date
    10-22-2012
    Location
    stockton, ca
    MS-Off Ver
    Excel 2003
    Posts
    29

    How to Add the Possibility of Letters into VBA formula

    Pretty new to Excel. Putting together a user form with 8 different text boxes. In those text boxes should be numbers the user puts in. I have a code that automatically add the numbers from the text boxes and input them into a cell on the worksheet (half into one, half into the other one). Problem is, I also have a checkbox option for no data to enter. When this is checked, I would like the 8 text boxes (4 at a time, 2 check boxes) to read "#N/A," which I have accomplished. I also want the sum of those 4 "#N/A"s to equal "#N/A" once the "okay" command button click event happens (to keep the integrity of a chart I have linked to the worksheet).

    Here is a piece of the VBA I have put together

    adds the 4 cells together and places on the sheet
    ActiveCell.Offset(5, 0) = CDbl(txtINDIVIDUALLY.Value) + CDbl(txtINTERPERSONALLY.Value) + CDbl(txtSOCIALLY.Value) + CDbl(txtOVERALL.Value)
    This isn't right obviously, but it's my best attempt so far.
        If CDbl(txtRELATIONSHIP.Value) + CDbl(txtGOALS.Value) + CDbl(txtAPPROACH.Value) + CDbl(txtOVERALLSRS.Value) = "#N/A" Then
        ActiveCell.Offset(5, 0) = "N/A"

    Here's more of the code that may be pertinent -
    Private Sub chkbxNOORS_Change()
        
        If Me.chkbxNOORS.Value = True Then
            Me.txtINDIVIDUALLY.Value = "#N/A"
            Me.txtINTERPERSONALLY.Value = "#N/A"
            Me.txtSOCIALLY.Value = "#N/A"
            Me.txtOVERALL.Value = "#N/A"
        Else
            Me.txtINDIVIDUALLY.Value = ""
            Me.txtINTERPERSONALLY.Value = ""
            Me.txtSOCIALLY.Value = ""
            Me.txtOVERALL.Value = ""
        End If
    
    End Sub
    
    Private Sub chkbxNOSRS_Change()
        
        If Me.chkbxNOSRS.Value = True Then
            Me.txtRELATIONSHIP.Value = "#N/A"
            Me.txtGOALS.Value = "#N/A"
            Me.txtAPPROACH.Value = "#N/A"
            Me.txtOVERALLSRS.Value = "#N/A"
        Else
            Me.txtRELATIONSHIP.Value = ""
            Me.txtGOALS.Value = ""
            Me.txtAPPROACH.Value = ""
            Me.txtOVERALLSRS.Value = ""
        End If
        
    End Sub
    
    Private Sub cmdOKAY_Click()
    
    Dim RowCount As Long
    Dim ctl As Control
        
    ActiveWorkbook.ActiveSheet.Activate
        Range("C10").Select
        Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(0, 1).Select
        End If
        
        Loop Until IsEmpty(ActiveCell) = True
        ActiveCell.Value = txtDATE.Value
        ActiveCell.Offset(1, 0) = txtINDIVIDUALLY.Value
        ActiveCell.Offset(2, 0) = txtINTERPERSONALLY.Value
        ActiveCell.Offset(3, 0) = txtSOCIALLY.Value
        ActiveCell.Offset(4, 0) = txtOVERALL.Value
        ActiveCell.Offset(5, 0) = CDbl(txtINDIVIDUALLY.Value) + CDbl(txtINTERPERSONALLY.Value) + CDbl(txtSOCIALLY.Value) + CDbl(txtOVERALL.Value)
        
        Range("C10").Select
    
        If CDbl(txtRELATIONSHIP.Value) + CDbl(txtGOALS.Value) + CDbl(txtAPPROACH.Value) + CDbl(txtOVERALLSRS.Value) = "#N/A" Then
        ActiveCell.Offset(5, 0) = "N/A"
        End If
    ActiveWorkbook.ActiveSheet.Activate
        Range("C17").Select
        Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(0, 1).Select
        End If
        Loop Until IsEmpty(ActiveCell) = True
        ActiveCell.Value = txtDATE.Value
        ActiveCell.Offset(1, 0) = txtRELATIONSHIP.Value
        ActiveCell.Offset(2, 0) = txtGOALS.Value
        ActiveCell.Offset(3, 0) = txtAPPROACH.Value
        ActiveCell.Offset(4, 0) = txtOVERALLSRS.Value
        ActiveCell.Offset(5, 0) = CDbl(txtRELATIONSHIP.Value) + CDbl(txtGOALS.Value) + CDbl(txtAPPROACH.Value) + CDbl(txtOVERALLSRS.Value)
        
        Range("C17").Select
    
        If CDbl(txtRELATIONSHIP.Value) + CDbl(txtGOALS.Value) + CDbl(txtAPPROACH.Value) + CDbl(txtOVERALLSRS.Value) = "#N/A" Then
        ActiveCell.Offset(5, 0) = "N/A"
        End If
    End Sub
    Last edited by JBeaucaire; 11-30-2012 at 08:50 PM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to Add the Possibility of Letters into VBA formula

    Maybe:

    If IsError(CDbl(txtRELATIONSHIP.Value) + CDbl(txtGOALS.Value) + CDbl(txtAPPROACH.Value) _
             + CDbl(txtOVERALLSRS.Value)) Then ActiveCell.Offset(5, 0) = "N/A"

    Don't forget code tags! Take a moment to read the Forum Rules, they will help you.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-22-2012
    Location
    stockton, ca
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: How to Add the Possibility of Letters into VBA formula

    Beautifully simplistic. I'll give it a whirl on Monday morning. Thanks and I will read the forum rules and use the code tags.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: How to Add the Possibility of Letters into VBA formula

    Why not check if the checkbox is clicked and if it isn't do the sum. if it is put #N/A in the cell?

    For example.
    If chkbxNOORS.Value = True Then
        ActiveCell.Offset(5,0)  ="#N/A"
    Else
        ActiveCell.Offset(5, 0) = CDbl(txtINDIVIDUALLY.Value) + CDbl(txtINTERPERSONALLY.Value) + CDbl(txtSOCIALLY.Value) + CDbl(txtOVERALL.Value)
    End If

    PS I think CDbl("#NA") mightr cause a Type mismatch error.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    10-22-2012
    Location
    stockton, ca
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: How to Add the Possibility of Letters into VBA formula

    So I ended up using Norie's code which works wonderfully. Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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