VB code to fill next available cell

G

GLHEC-BLS

I have two different workbooks, a test book and a results book. I would like
to have a command button, that when clicked, opens the results workbook and
fill the users name and answers in the appropriate columns, say A1 through
G1. Then it saves the results workbook, closes it, and clears the contents of
the cells in the test workbook that contains the answers the user selected.
Then when someone else takes the test and does the same thing, their answers
are saved BELOW the first person in the results workbook, allowing me to use
the same test workbook and log everyone's results n the same workbook. I know
how to call open a new workbook, save and close it, and clear the contents,
but what I don't know is how to get the second or third or fourth users
answers to be entered in the row below the person before them. Hope this
makes sense and someone can help. Thanks!
 
S

Sheeloo

The following code fragment will give you the last row used, in Col A, on
Data Sheet
in the variable LastRow... Add 1 to it and write to that row...
Dim LastRow As Long

With Worksheets("Data")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

End With
MsgBox LastRow
 
G

GLHEC-BLS

That works great, but I don't understand the last part about adding 1. I
understand this is supose to tak eit to the row below the one with the last
entry, but I'm not sure where you mean to add the + 1 to the variable
LastRow. This is what I have right now.

Private Sub Worksheet_Activate()
Dim LastRow As Long

With Worksheets("Learning Style")
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Select

End With

End Sub
 
S

Susan

do it this way:

LastRow = .Cells(.Rows.Count, "B").End(xlUp) + 1
LastRow.Select

:)
susan
 
S

Sheeloo

What I had meant was that LastRow will give you the last filled row. So if
you want to write to the next row you will have to add 1 to LastRow
variable...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top