User Form -Empty Textboxes

yeminbek

New Member
Joined
Jun 29, 2012
Messages
2
Hi friends,.thanks for any help.

I have a userform and it has 50 text boxes in it. and I write the values in the textboxes to the excell sheet when user press click on the userform.

My problem is; generally i dont need to fill all text boxes. For example I fill 5 of them. And when I click, I see these 5 values in the excel sheet as expected.

However when I use Application.CountA.....vba code to count the cells which is not empty, it always shows 50...However 5 of the cells shows value.

Any help really appreciated, I am in trouble
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

vaskov17

Well-known Member
Joined
Apr 27, 2011
Messages
920
When you click, you should go through the textboxes and only add the ones that have some text and not the empty ones.
 

yeminbek

New Member
Joined
Jun 29, 2012
Messages
2
Thank you very much..I am adding all the text boxes with below code...How can I add only text boxes which has values?

Private Sub CommandButton1_Click()

Dim i As Double
For i = 1 To 50
ThisWorkbook.Sheets("Sheet6").Cells(i , 1).Value = UserForm1.Controls("textbox" & i)

Next i

UserForm1.Hide
End Sub
 

vaskov17

Well-known Member
Joined
Apr 27, 2011
Messages
920
Code:
Private Sub CommandButton1_Click()
    Dim i As Integer
    For i = 1 To 50
        If Trim(UserForm1.Controls("textbox" & i).Text) <> "" Then
            ThisWorkbook.Sheets("Sheet6").Cells(i, 1).Value = UserForm1.Controls("textbox" & i)
        End If
    Next i
    UserForm1.Hide
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,721
Messages
5,597,758
Members
414,171
Latest member
12Rev79

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