0

I have a Combobox in my Spreadsheet. I am trying to get the selected value from it. But not been able to do so.

These are the Codes that I tried:

Range("A1")=ComboBox1.SelectedItem

And

Range("A1")=ComboBox1.Value

Kindly help me with this. They both are not working.

This is how I added the Items to the Combobox:

For i = 2 To lastnum        
    disName= ThisWorkbook.Sheets(final).Range(Col& i).Value        
    With wb21Tool.Sheets("Main").ComboBox1        
        .AddItem disName        
    End With        
Next
6
  • What error do you get? Range("A1")=ComboBox1.Value should work! Commented May 9, 2017 at 11:59
  • @MiguelH Object required - error Commented May 9, 2017 at 12:00
  • Try fully qualify your objects, try wb21Tool.Sheets("Main").Range("A1").Value = wb21Tool.Sheets("Main").ComboBox1.Value , it worked for me Commented May 9, 2017 at 12:01
  • @ShaiRado Worked. Can you add it as an answer. I will accept it. Thanks. Commented May 9, 2017 at 12:02
  • Do you add items to the combobox in the 'ThisWorkbook' 'Workbook_open()' object? Commented May 9, 2017 at 12:03

1 Answer 1

3

You need to fully qualify your objects, try:

wb21Tool.Sheets("Main").Range("A1").Value = wb21Tool.Sheets("Main").ComboBox1.Value 

Or,

With wb21Tool.Sheets("Main")
    .Range("A1").Value = .ComboBox1.Value 
End With
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.