VBA help needed

nlietuva

New Member
Joined
Feb 1, 2022
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hello,
I'm trying to make a ComboBox selection text copier. In code i wrote what is the answer of each question if its YES or No selected. Can someone help me how to write a code if there are not all the questions selected but copy only the answered questions text. I dont want to write all possible ways using "if".

1643725474241.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Are these the only comboxes that you have on the form?

Do you use a naming convention for the combobox and label controls?
 
Upvote 0
Are these the only comboxes that you have on the form?

Do you use a naming convention for the combobox and label controls?
Yes only these 9 comboboxes and what do you mean by saying "naming convention" can you give a short example?
 
Upvote 0
Naming Convention e.g.

cboQuestion1
cboQuestion2
cboQuestion3
cboQuestion4

When you say 'answered questions text' is this taken from the label to the left of the ComboBox?

Do the Labels have a naming convention? e.g.

lblQuestionLabel1
lblQuestionLabel2
lblQuestionLabel3
lblQuestionLabel4
 
Upvote 0
Naming Convention e.g.

cboQuestion1
cboQuestion2
cboQuestion3
cboQuestion4

When you say 'answered questions text' is this taken from the label to the left of the ComboBox?

Do the Labels have a naming convention? e.g.

lblQuestionLabel1
lblQuestionLabel2
lblQuestionLabel3
lblQuestionLabel4
Yes, i finally fixed that, but now I have new problem if i choose for ex. ComboBox1 and ComboBox4, in between of two answers there are 2 empty lines because i didnt choose ComboBox2 and ComboBox3. Im using & vbNewLine &. So maybe you know how to fix that?
 
Upvote 0
To collect the answers you can set up a loop that loops through each ComboBox in turn.

This is where the logical naming convention comes in where the suffix on the end of the ComboBox name
is the number of the question.

I'm not sure what you want to do with the answers so I have just put them into a string and displayed this as a message.

VBA Code:
Dim ctrl As Control
Dim i As Integer
Dim strResults As String

    For i = 1 To 8
            
        Set ctrl = Me.Controls("ComboBox" & i)
        
        If ctrl.value <> "" Then
        
            strResults = strResults & vbCrLf & ctrl.value
            
        End If
    
    Next i
    
    MsgBox strResults
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,994
Latest member
rohitsomani

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