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.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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).
 
Upvote 0
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:
 
Upvote 0
You are welcome.
Glad to help!:)
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top