Excel VBA? How to I write the value of my text box onto the next available cell in column a?

I have 2-3 textboxes. when I click the commandbutton1, i like to write the value of textbox1 onto sheet 2, column A and textbox2 to column B? How to do i get it to go to the next record if the previous record already has data in it?

Since you may be entering new values from day to day, I assume you want the code to check for the last used cell within the range of data and then add data to the next row of cells.

I will assume that the current sheet you are adding data to is the active sheet. What you will need is the SpecialCells method with the "xlCellTypeLastCell" type value, followed a simple addition of one to where it found. This example selects the last cell in the used range of the worksheet:

ActiveSheet.Cells.SpecialCells( xlCellTypeLastCell ).Activate

And if you followed that by the following line of code:

Cells(ActiveCell.Row + 1, 1).Activate

Then it would make the next available cell in column A as active, waiting for you to store whatever value you want in it.

Leave a Reply