Hello,
I know that similar questions have been asked before, but I am having difficulty translating the solutions into something I can use.
I have devised a data entry form, which needs to paste the data into the spreadsheet on the next empty row at the bottom. The procendure runs when you click the "Next Patient" button. There are 10 fields for each patient (arranged into columns, left to right); Site number, ICDF number, case number, nhs number, surname, first name, drus approved, consultant, active y/n/p and notes.
The Column titles are held in row 3, columns A to J, with the data to be netered below.
This is sort of working, but sometimes seems to overwrite the bottom line of data previously entered (doesnt seem to do it every time though, which is strange?)
This is what I have been using:
Private Sub nextrecordbutton_Click()
Unload Me
Dim emptyRow As Long
Sheet1.Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
Cells(emptyRow, 1).Value = sitecombo.Value
Cells(emptyRow, 2).Value = ICDFnotext.Value
Cells(emptyRow, 3).Value = casenotext.Value
Cells(emptyRow, 4).Value = NHSnotext.Value
Cells(emptyRow, 5).Value = surnametext.Value
Cells(emptyRow, 6).Value = firstnametext.Value
Cells(emptyRow, 7).Value = drugcombo.Value
Cells(emptyRow, 8).Value = consultantcombo.Value
Cells(emptyRow, 9).Value = activecombo.Value
Cells(emptyRow, 10).Value = notestext.Value
patientdetailsform.Show
End Sub
Can anyone see what I might be doing wrong for it not to always find the next blank row to paste into?
Or is there a better way than the method I have used? I am still quite a beginner with VBA.
Thanks in anticipation.
I know that similar questions have been asked before, but I am having difficulty translating the solutions into something I can use.
I have devised a data entry form, which needs to paste the data into the spreadsheet on the next empty row at the bottom. The procendure runs when you click the "Next Patient" button. There are 10 fields for each patient (arranged into columns, left to right); Site number, ICDF number, case number, nhs number, surname, first name, drus approved, consultant, active y/n/p and notes.
The Column titles are held in row 3, columns A to J, with the data to be netered below.
This is sort of working, but sometimes seems to overwrite the bottom line of data previously entered (doesnt seem to do it every time though, which is strange?)
This is what I have been using:
Private Sub nextrecordbutton_Click()
Unload Me
Dim emptyRow As Long
Sheet1.Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
Cells(emptyRow, 1).Value = sitecombo.Value
Cells(emptyRow, 2).Value = ICDFnotext.Value
Cells(emptyRow, 3).Value = casenotext.Value
Cells(emptyRow, 4).Value = NHSnotext.Value
Cells(emptyRow, 5).Value = surnametext.Value
Cells(emptyRow, 6).Value = firstnametext.Value
Cells(emptyRow, 7).Value = drugcombo.Value
Cells(emptyRow, 8).Value = consultantcombo.Value
Cells(emptyRow, 9).Value = activecombo.Value
Cells(emptyRow, 10).Value = notestext.Value
patientdetailsform.Show
End Sub
Can anyone see what I might be doing wrong for it not to always find the next blank row to paste into?
Or is there a better way than the method I have used? I am still quite a beginner with VBA.
Thanks in anticipation.