+ Reply to Thread
Results 1 to 3 of 3

Defining textbox value as a variable

  1. #1
    Registered User
    Join Date
    06-10-2013
    Location
    Nantes
    MS-Off Ver
    Excel 2010
    Posts
    2

    Defining textbox value as a variable

    Hello to everybody;

    I have a Userform with a Textbox named Lead Time. What I want to do is to enter a value to the lead Time Textbox and saved it on a worksheet. I then use the saved value as a variable in my code (lead time variable). The problem is that each time the code executes, it picks up the Text/value property value as a leadtime variable value instead of the one I assigned via Textbox. If i leave blank the text property of the Textbox, the code considers Leadtime of Zero.

    I checked many threads but none is working for me.

    Thanks in advance

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Defining textbox value as a variable

    do the veriables have the same name?
    also if you are saving it to a cell do you need to make it a variable again? (couldn't you just ref the cell?)

  3. #3
    Registered User
    Join Date
    06-10-2013
    Location
    Nantes
    MS-Off Ver
    Excel 2010
    Posts
    2

    Post Re: Defining textbox value as a variable

    Thanks Leon for the reply.
    First i populate cells with a Userform (but the range is not fixed). Then i refer to the cells' values using variables. For example for the lead Time Textbox, I enter a value let's suppose 3. This value is saved on a sheet. Then i reference the saved value using a variable i.e. intLT (Leadtime variable) in a code. Also, the textbox name and the variable name is not the same. Textbox name is LTBox and variable referring to the box value is intLT (an integer).

    Below is the code;

    Sub PlannedOrderRelease()

    Dim POR As Long ' Planned Order Receipt
    Dim intLT as integer ' Value that i entered via LeadTime TextBox and saved on a worksheet

    Set MRP = Sheets("MRP")

    For POR = 3 To MRP.Cells(8, 3).End(xlToRight).Column

    If MRP.Cells(8, POR).Value = 0 Then

    MRP.Cells(8, POR).Offset(1, -intLT).Value = ""
    Else

    MRP.Cells(8, POR).Offset(1, -intLT).Value = MRP.Cells(8, POR) ' offseting value in the immediate row below using a variable intLT

    End If

    Next


    End Sub
    Last edited by roarwali; 12-18-2013 at 09:27 AM.

+ 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. Defining a variable as Vlookup
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-08-2013, 07:13 PM
  2. Using a variable when defining a range
    By Newbie_Nick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2009, 04:47 AM
  3. Defining a Variable
    By Phil H in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2006, 07:10 AM
  4. defining number range in textbox
    By Ouka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2006, 05:00 AM
  5. defining a textbox
    By funkymonkUK in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-09-2005, 06:29 AM

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