![]() |
VB code to fill next available cell
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! |
VB code to fill next available cell
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 "GLHEC-BLS" wrote: 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! |
VB code to fill next available cell
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 "Sheeloo" wrote: 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 "GLHEC-BLS" wrote: 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! |
VB code to fill next available cell
do it this way:
LastRow = .Cells(.Rows.Count, "B").End(xlUp) + 1 LastRow.Select :) susan On Nov 12, 1:06*pm, GLHEC-BLS wrote: 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 "Sheeloo" wrote: 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 "GLHEC-BLS" wrote: 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!- Hide quoted text - - Show quoted text - |
VB code to fill next available cell
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... "GLHEC-BLS" wrote: 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 "Sheeloo" wrote: 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 "GLHEC-BLS" wrote: 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! |
All times are GMT +1. The time now is 02:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com