ActiveX Text boxes to autofill "N/A" based on value selected on a ComboBox

quanweitkd

New Member
Joined
Apr 8, 2021
Messages
22
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I created a form using activeX tools. I want it in a way that when the form user selects "1" for question 4 (ComboBox), then on question 5, besides the first textbox is kept blank, the other 9 textboxes will autofill with "N/A".
Then if user selects "2" for question 4, then on question 5, besides the first and second textboxes are kept blank, the other 8 textboxes will autofill with "N/A", and so on.
I am new to VBA, please advise how can I achieve this? Thanks a million!

1617865774382.png
I
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I realised this forum doesn't allow me to attach any excel files.
 
Upvote 0
VBA Code:
Sub SLAnum_change()
    If SLAnum.Value <> 0 Then
        For Row = 1 To SLAnum.Value
            Sheets("Form").OLEObjects("P" & Row & "TextBox").Object.Text = ""
        Next Row
        For Row = SLAnum.Value + 1 To 10
            Sheets("Form").OLEObjects("P" & Row & "TextBox").Object.Text = "N/A"
        Next Row
    End If
End Sub
 
Upvote 0
Solution
VBA Code:
Sub SLAnum_change()
    If SLAnum.Value <> 0 Then
        For Row = 1 To SLAnum.Value
            Sheets("Form").OLEObjects("P" & Row & "TextBox").Object.Text = ""
        Next Row
        For Row = SLAnum.Value + 1 To 10
            Sheets("Form").OLEObjects("P" & Row & "TextBox").Object.Text = "N/A"
        Next Row
    End If
End Sub
It works! Thank you Sir!
 
Upvote 0
easier with sheet to actually see what is needed, at least for me anyway :)
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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