Consulting

Results 1 to 17 of 17

Thread: Solved: find number then +1

  1. #1

    Solved: find number then +1

    hi
    i have a textbox that i would like to display the next number in a list.
    the list is on a sheet and is a list of job numbers, 12001,12002 ect ect,
    when i open a userform i want the textbox to display the next number, so if the last number in the list is 12002 i want the textbox in the userform to disply 12003,
    how can i do this?
    thanks ash

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Dim vec As Variant

    vec = Split(ActiveCell.Value, ",")
    Me.Textbox1.Text = vec(UBound(vec)) + 1
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    where in that code do i put the cell to start looking for the list?
    the list is on shhet 2 and starts in column 2 row 3

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I thought all of the numbers were in one cell.
    You probably need

    [vba]
    Me.TextBox1.Text = Application.Max(Worksheet("Sheet2").Columns(2)) + 1[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    the numbers are all in there own rows, so 12001 in row 3, 12002 in row 4 ect ect, i need it to find the last row with data and add 1 to that number.
    thank you

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Number in the last row, or the highest number?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    well they go in order as it a job number and as a job comes in thats the next number. so starts the year at 12001, then 12002 ect ect which is why i want the text box to display the last rows number +1 as the userform is creating a new job so will the job next number

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Then MAX() + 1 should do it fine.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    ok do i need to tell it which column and row to start looking in?

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,065
    Location
    Place it in the column below the current last number
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  11. #11
    but i need it to be displayed in textbox in a userform.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post #4 gave you what you want.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    ah thank you
    i am getting an error : compile error, sub or function not defined
    here is the code i have used

    Private Sub UserForm_Initialize()
    Me.txtjobNumber.Text = Application.Max(Worksheet("sheet4").Columns(2)) + 1
    End Sub

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry, it should be Worksheets not Worksheet.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    its now saying subscript out of range

  16. #16
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That means you don't have a Sheet4.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  17. #17
    i get confused because sometimes the code is the worksheet code not the worksheet name, changed it to the worksheet name and is now workinmg perfect. thank you so much for your help.

Posting Permissions

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