+ Reply to Thread
Results 1 to 16 of 16

help to convert textbox value to negative based on another textbox value

Hybrid View

  1. #1
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    help to convert textbox value to negative based on another textbox value

    Trying to figure out the else if and not even coming close.

    What I am trying to accomplish if texbox1 value = "stock: then it will take textbox1 and
    fill the cell with a positive number . If textbox1 = 123456 or any number that is not "stock"
    it would put that cell as negative. I need to do this for textbox 2 to textbox10

    code below works to put it into the worksheet until I tried to play with the else .
    As you can see totaly new to this

    NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            
            If UserForm1.TextBox1.Value = "stock" Then
            .Cells(NextRw, 1).Value = UserForm1.TextBox2.Value 
            Else
            .Cells(NextRw, 1).Value = UserForm1.TextBox2.Value* -1
    
            .Cells(NextRw, 2).Value = Date
            End With     
            .Cells(NextRw, 3).Value = UserForm1.TextBox2.Value
            .Cells(NextRw, 4).Value = UserForm1.TextBox4.Value
            .Cells(NextRw, 5).Value = UserForm1.TextBox5.Value
            .Cells(NextRw, 6).Value = UserForm1.TextBox6.Value
            .Cells(NextRw, 7).Value = UserForm1.TextBox7.Value
            .Cells(NextRw, 8).Value = UserForm1.TextBox8.Value
            .Cells(NextRw, 9).Value = UserForm1.TextBox9.Value
            .Cells(NextRw, 10).Value = UserForm1.TextBox10.Value
    Thanks in advance if anyone wishes to help me.
    Lewis

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: help to convert textbox value to negative based on another textbox value

    if strings.left(userform1.textbox1.value,5) = "stock" then
      .cells(NextRw,1).value = userform1.textbox2.value
    else
      .cells(NextRw,1).value = -1
    end if

  3. #3
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    Must have done something wrong as all I am getting on anything other than "stock"
    is negative 1 in column 3 (instead of the negative value of what was inputted into
    the userform textbox2 (But I'm a step closer it think lol.

    Thanks again Ragulduy but can you see what I did wrong. Code snippet below .

    Sub AddData()
        
        With Sheet1
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = UserForm1.TextBox1.Value
            .Cells(NextRw, 2).Value = Date
    
           If Strings.Left(UserForm1.TextBox1.Value, 3) = "stock" Then
      .Cells(NextRw, 3).Value = UserForm1.TextBox2.Value
    Else
      .Cells(NextRw, 3).Value = -1
    End If
           
            .Cells(NextRw, 4).Value = UserForm1.TextBox3.Value
            .Cells(NextRw, 5).Value = UserForm1.TextBox4.Value
            .Cells(NextRw, 6).Value = UserForm1.TextBox5.Value
            .Cells(NextRw, 7).Value = UserForm1.TextBox6.Value
            .Cells(NextRw, 8).Value = UserForm1.TextBox7.Value
            .Cells(NextRw, 9).Value = UserForm1.TextBox8.Value
            .Cells(NextRw, 10).Value = UserForm1.TextBox9.Value
            .Cells(NextRw, 11).Value = UserForm1.TextBox10.Value
            
           
     MsgBox "Entry Added"
          End With
        
        End Sub

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: help to convert textbox value to negative based on another textbox value

    Sorry, I misread what you wanted, change:
      .Cells(NextRw, 3).Value = -1
    to
      .Cells(NextRw, 3).Value = -UserForm1.TextBox2.Value

  5. #5
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    oops spoke to fast just tested one with the text stock and it also came negative lol.

    this is what I have now did I muck it up ?

           If Strings.Left(UserForm1.TextBox1.Value, 3) = "stock" Then
      .Cells(NextRw, 3).Value = UserForm1.TextBox2.Value
    Else
      .Cells(NextRw, 3).Value = -UserForm1.TextBox2.Value
    End If

  6. #6
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    AMAZING thank you so much.
    Now just need to copy this loop for 10 textboxes lol.

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: help to convert textbox value to negative based on another textbox value

    you changed:
    if strings.left(userform1.textbox1.value,5) = "stock" then
    to
     If Strings.Left(UserForm1.TextBox1.Value, 3) = "stock" Then

  8. #8
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    only ask because when I tried to do the next set and put the value,5 it didn't work.
    The first column works to be positive if "stock" appears but second column always goes negative when it says "stock"

    Sub AddData()
        
        With Sheet1
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = UserForm1.TextBox1.Value
            .Cells(NextRw, 2).Value = Date
    
           If Strings.Left(UserForm1.TextBox1.Value, 5) = "stock" Then
      .Cells(NextRw, 3).Value = UserForm1.TextBox2.Value
    Else
      .Cells(NextRw, 3).Value = -UserForm1.TextBox2.Value
    End If
    
    If Strings.Left(UserForm1.TextBox2.Value, 5) = "stock" Then
      .Cells(NextRw, 4).Value = UserForm1.TextBox3.Value
    Else
      .Cells(NextRw, 4).Value = -UserForm1.TextBox3.Value
    End If

  9. #9
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    oops sorry see my error. with the second set

  10. #10
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    your right and it works when I put it back to 5.
    Can you tell me what the value,5 means I thought it was in reference to the column number which was 3 and
    of course I am wrong.

    Thanks again for your time

  11. #11
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    Can I ask you another question since you have helped me so much.

    What if I want to have a checkbox for Stock and when you click
    on the checkbox for stock it would fill in .Cells(NextRw, 1).Value with the word stock (instead of having to type it in) and continue your loop with cells being positive.




    Is this complicated to do ?

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: help to convert textbox value to negative based on another textbox value

    Hi - the LEFT(a,b) function takes the string a and returns the first b letters. So it returns the first 5 letters of whatever is in the textbox and compares it to "stock".

    I'd suggest posting another thread for your new question.

  13. #13
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    btw I only get the error if I do not enter "stock" . If I enter "stock there is no error when clicking add"

  14. #14
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    sorry I have some typos causing my problems. Again thanks for the help.

  15. #15
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    your right I will post another thread for the other question.

    I do have something happening weird now. the positive based on stock or negative based on anything else is working perfect but the code you gave me affected code elsewhere on my userform.

    The userform1 was totaling the textboxes and it works fine still but as soon as I click add I get an error.

    the userform code that works on userform display but mucks up your code is .

    Private Sub TextBox2_Change()
    TextBox11 = Val(TextBox2)
    End Sub
    Private Sub TextBox3_Change()
    TextBox11 = Val(TextBox2) + Val(TextBox3)
    End Sub
    Private Sub TextBox4_Change()
    TextBox11 = Val(TextBox2) + Val(TextBox3) + Val(TextBox4)
    End Sub
    and the error on submit goes to this line with a type mismatch.

    .Cells(NextRw, 5).Value = -UserForm1.TextBox4.Value

    Is there something I need to change in the userform subtotal to match your new code ?

  16. #16
    Registered User
    Join Date
    05-10-2013
    Location
    montreal
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: help to convert textbox value to negative based on another textbox value

    I'm still having an issue even though I double checked I have no typos.

    code works as long as I start from the first column and do not skip any.
    but the minute I skip a column I get a type mismatch error.

    to explain :
    column 1 is either a po number or the term stock (adjust numbers positive or negative)
    column 2 is the date
    column 3 is first size
    column 4 is second size
    etc

    so as long as I do not skip column 1,2,3,4 it works perfect but if I add
    to column 1,2 skip 3 and put a qty in column 4 it bombs.


    can anyone see what I did wrong.
    code below...
    Dim NextRw As Long
    Sub AddData()
        
        With ActiveSheet
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            .Cells(NextRw, 1).Value = UserForm1.TextBox1.Value
            .Cells(NextRw, 2).Value = Date
    
    If Strings.Left(UserForm1.TextBox1.Value, 5) = "stock" Then
      .Cells(NextRw, 3).Value = UserForm1.TextBox2.Value
    Else
      .Cells(NextRw, 3).Value = -UserForm1.TextBox2.Value
    End If
    
    If Strings.Left(UserForm1.TextBox1.Value, 5) = "stock" Then
      .Cells(NextRw, 4).Value = UserForm1.TextBox3.Value
    Else
      .Cells(NextRw, 4).Value = -UserForm1.TextBox3.Value
    End If
    
    If Strings.Left(UserForm1.TextBox1.Value, 5) = "stock" Then
       .Cells(NextRw, 5).Value = UserForm1.TextBox4.Value
    Else
      .Cells(NextRw, 5).Value = -UserForm1.TextBox4.Value
    End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 01-29-2014, 05:53 AM
  2. Set Max and Min limits on calculated textbox based on another textbox entry
    By kpinkerman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2013, 04:54 PM
  3. Replies: 3
    Last Post: 05-07-2012, 09:46 PM
  4. [SOLVED] Textbox fomatting value based on another textbox
    By job in forum Excel General
    Replies: 2
    Last Post: 02-02-2005, 01:06 PM

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