UserForm in a Specific range

JessyVal

New Member
Joined
Feb 23, 2021
Messages
30
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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
 
Upvote 0
Solution
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!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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