PDA

View Full Version : get last cell value and add 1 for next number



miketallica
09-21-2009, 01:59 PM
okay, i have a document that has a userform pop up when you open it. you fill out the form and it finds the next blank row and inputs the information.

what i would like to do is automatically populate the first textbox of the user form with the next number.

what i mean is that the column A is a list of numbers each number is 1 greater than the last

example;

1
2
3
4
5


you get it.....right?

Dodgeitorels
09-21-2009, 02:10 PM
Sheets("Sheet2").Select

nextrow = Cells.Find(what:="*", searchdirection:=xlPrevious, searchorder:=xlByRows).Row + 1
Cells(nextrow, 1).Select
ActiveCell.FormulaR1C1 = "=ROW()-1"
ActiveCell.Offset(0, 1).Range("A1").Select



and so on will number next row and move to next cell to right of numbered cell. To put in textbox in userform I would like to know answer also.

............... I think!!! :doh:

ndendrinos
09-21-2009, 02:41 PM
maybe this can help

miketallica
09-21-2009, 02:45 PM
there wasnt any code in the file. but i looked like it might be what im looking for.

Dodgeitorels
09-21-2009, 03:23 PM
miketallica, didn't you say you were taking courses for this stuff? There is code in that file, I am very very new to vba and knew where to look. I am curious to the file you said you had been working on for some time before your classes started. Anyway, I find being straight up is always best.

miketallica
09-21-2009, 03:30 PM
weird, i dont know why but when i opened it the first time i got all kinds of errors and there wasnt any code. believe me i know where to look as well. i just figured the file was corrupt. what are you curious about.

ndendrinos
09-21-2009, 03:53 PM
miketallica the sample I posted should work like clock work
I'm curious to learn what could have possibly gone wrong.
As for the code in VBA bring up the form and double click on the first text box.
Copy the code and incorporate same in your file or better still publish your file so that you get help from the experts here. (I'm not one by any long shot... just learning like you)

ndendrinos
09-21-2009, 04:32 PM
If you are going to use this to add data on the sheet you are working from AND since column A is filled with numbers this modified example should do the trick