Linking VBA combobox to named Worksheet Cell Range

jparfitt87

New Member
Joined
Jul 13, 2012
Messages
23
Hi all, kinda new to VBA and have become stuck on something.....

I have a VBA Userform which i'm using as a feedback survey.

Within the excel Sheet (which will later be hidden) I have the questions linked to the Labels within the Userform, next to the questions it has a list validation for which answers are needed IE agree, Satisfied, Very Good. These are name Answer_Set_1, Answer_Set_2 etc. the different range of answers are within their own sheet called "Answers" and the ranges are dynamically named according the the list validation.

What I need to do is link the combo box within the VBA userform to show the answers depending on the list validation selected....

This is what I'm thinking......

If Worksheets("Questions").Range(ResponceQ1AV) = "Answer_Set_1" Then
FrmScope.CmbQ1 = Worksheets("Answers").Range(Answer_Set_1)
End If

But I get an application defined or object defined error.

Does any one have anything that could help, or explain to me (in simple terms) where i'm going wrong??

Thanks in advance
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Within the excel Sheet (which will later be hidden) I have the questions linked to the Labels within the Userform, next to the questions it has a list validation for which answers are needed IE agree, Satisfied, Very Good. These are named Answer_Set_1, Answer_Set_2 etc. the different range of answers are within their own sheet called "Answers" and the ranges are dynamically named according the the list validation.

If Worksheets("Questions").Range(ResponceQ1AV) = "Answer_Set_1" Then
FrmScope.CmbQ1 = Worksheets("Answers").Range(Answer_Set_1)
End If

But I get an application defined or object defined error.

Are Answer_Set_1, Answer_Set_2, etc. Defined Names on the worksheet or VBA variables? If they are Defined Names, then they need to be surrounded with quote marks inside the Range property call (otherwise VB thinks they are normal variables)...

FrmScope.CmbQ1 = Worksheets("Answers").Range("Answer_Set_1")
 
Upvote 0
Hi Rick, I've tried it with the quotations and now gives me a new error "Could not set the value property".

If Worksheets("Questions").Range("ResponceQ1AV") = "Answer_Set_1" Then
FrmScope.CmbQ1 = Worksheets("Answers").Range("Answer_Set_1")
End If
 
Last edited:
Upvote 0
Hi Rick, I've tried it the the quotations which gets me past the error message however the combo box doesn't have anything populate in it.

If Worksheets("Questions").Range("ResponceQ1AV") = "Answer_Set_1" Then
FrmScope.CmbQ1 = Worksheets("Answers").Range("Answer_Set_1")
End If

Okay, try using this for the assignment line instead of what you show above...

FrmScope.CmbQ1.List = Worksheets("Answers").Range("Answer_Set_1").Value

Note the specifying of the List and Value properties... those are important.
 
Upvote 0
this works amazingly thank you!!!

I also need help on how to loop through all the different options but i guess that would be a new thread??
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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