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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi and welcome to MrExcel
What are the names of your textboxes and combobox. is this a userform or a worksheet
 
Upvote 0
The name of my combobox is "SLAnum".
The names of my 10 textboxes are "P1TextBox", "P2TextBox", "P3TextBox", "P4TextBox", "P5TextBox", "P6TextBox", "P7TextBox", "P8TextBox", "P9TextBox", "P10TextBox".
It is a worksheet.
 
Upvote 0
VBA Code:
Sub SLAnum_change()
    If SLAnum.Value<>0 then
        For row= SLAnum.Value +1 to 10
            Sheets(" enter your sheet name ").Shapes("P" & SLAnum.Value & "TextBox").Text = "N/A"
        Next Row
    End If
End Sub
 
Upvote 0
Hi and welcome to MrExcel
What are the names of your textboxes and combobox. is this a userform or a worksheet

VBA Code:
Sub SLAnum_change()
    If SLAnum.Value<>0 then
        For row= SLAnum.Value +1 to 10
            Sheets(" enter your sheet name ").Shapes("P" & SLAnum.Value & "TextBox").Text = "N/A"
        Next Row
    End If
End Sub
On my VBA editor, I double clicked on the worksheet "FORM" (the sheet that contains the textboxes and combobox) then pasted your code.
then according to your instructions, I enter the sheet name into the code this way:

Sub SLAnum_change()
If SLAnum.Value <> 0 Then
For Row = SLAnum.Value + 1 To 10
Sheets(Form).Shapes("P" & SLAnum.Value & "TextBox").Text = "N/A"
Next Row
End If
End Sub

But this error pops up:
Did I perform some steps wrongly?

1617871287369.png
 
Upvote 0
see if this works. i am not able to test it
VBA Code:
Sheets("Form").Shapes("P" & SLAnum.Value & "TextBox").Value = "N/A"
 
Upvote 0

Forum statistics

Threads
1,214,869
Messages
6,122,012
Members
449,060
Latest member
LinusJE

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