VBA Entering data from a form into the next blank line

Dicegirly

New Member
Joined
Oct 26, 2015
Messages
10
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,493
Office Version
365
Platform
Windows
Welcome to the Board!

Try this calculation of emptyRow instead:
Code:
[COLOR=#333333]emptyRow = Cells(Rows.Count,"A").End(xlUp).Row + 1[/COLOR]
This actually goes to the last row with data in column A, then moves down one row (to the first available row).
 

Dicegirly

New Member
Joined
Oct 26, 2015
Messages
10
Welcome to the Board!

Try this calculation of emptyRow instead:
Code:
[COLOR=#333333]emptyRow = Cells(Rows.Count,"A").End(xlUp).Row + 1[/COLOR]
This actually goes to the last row with data in column A, then moves down one row (to the first available row).
Thank you so much, this indeed seems to fix it!
You are a star :cool:
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,493
Office Version
365
Platform
Windows
You are welcome.
Glad to help!:)
 

Forum statistics

Threads
1,082,151
Messages
5,363,430
Members
400,736
Latest member
Aida

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top