UserForm in a Specific range

JessyVal

New Member
Joined
Feb 23, 2021
Messages
29
Office Version
  1. 365
Hi guys, I hope someone Can help with the following:

Have created a table that is filled using a form. I would like to specify that the form can have a range of 29 entries. Because I can only have 29 beds, as the time going pass, when patients are discharged i can delete an entry manually. Then the next tim ethe form is completed it needs to add the new entry to this empty row.

1614104716437.png


For example, I don't have a registered user in row 2, with the user form I need to put the next data into that row. I have this code in VBA

Private Sub CommandButtonSave_Click()

Dim fill As Long

Sheets("Ward_Planner").Activate
fill = WorksheetFunction.CountA(Range("A:A")) + 1

Cells(fill, 1).Value = ComboBoxBed.Value
Cells(fill, 2).Value = TextBoxName.Value
Cells(fill, 3).Value = ComboBoxConsultant.Value
Cells(fill, 4).Value = TextBoxPcn.Value
Cells(fill, 5).Value = TextBoxDoa.Value
Cells(fill, 6).Value = ComboBoxGender.Value
Cells(fill, 7).Value = ComboBoxStatus.Value
Cells(fill, 8).Value = ComboBoxDiet.Value
Cells(fill, 9).Value = TextBoxComments.Value

Unload Me
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
   Dim fill As Long

   Sheets("Ward_Planner").Activate
   On Error Resume Next
   fill = Range("A2:A29").SpecialCells(xlBlanks)(1).Row
   On Error GoTo 0
   If fill = 0 Then
      MsgBox "all beds are filled"
      Exit Sub
   End If
   Cells(fill, 1).Value = ComboBoxBed.Value
   Cells(fill, 2).Value = TextBoxName.Value
 
Solution

JessyVal

New Member
Joined
Feb 23, 2021
Messages
29
Office Version
  1. 365
How about
VBA Code:
   Dim fill As Long

   Sheets("Ward_Planner").Activate
   On Error Resume Next
   fill = Range("A2:A29").SpecialCells(xlBlanks)(1).Row
   On Error GoTo 0
   If fill = 0 Then
      MsgBox "all beds are filled"
      Exit Sub
   End If
   Cells(fill, 1).Value = ComboBoxBed.Value
   Cells(fill, 2).Value = TextBoxName.Value

Thank you so sooooooo much! it works perfect!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,310
Messages
5,641,450
Members
417,210
Latest member
rins

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
Top