Userform help: Transfer selection from drop down list to worksheet range

Moonbeam111

Board Regular
Joined
Sep 24, 2018
Messages
85
Office Version
  1. 365
  2. 2010
Hi all. I have created a userform combobox with 4 items. One from each of range("D135:D138"). I have it initialized with this data:

VBA Code:
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Worksheets("Sheet1").Range("D135:D138").Value
end sub
The combo box does appear. It shows the 4 items in the dropdown list, however I dont know how to configure the command button. I have a value in Range("F136") [lets call it oranges] I want to copy the word oranges based on the item I choose.

Lets say we have these as the 4 items:

Apples in range d135
Pears in range d136
Bananas in range d137
Grapes in range d138

If I select Pears I want it to replace the word pears with the word in range("F136") [Oranges]

I am new to using user forms so I cannot figure out how to do this.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi all. I have created a userform combobox with 4 items. One from each of range("D135:D138"). I have it initialized with this data:

VBA Code:
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Worksheets("Sheet1").Range("D135:D138").Value
end sub
The combo box does appear. It shows the 4 items in the dropdown list, however I dont know how to configure the command button. I have a value in Range("F136") [lets call it oranges] I want to copy the word oranges based on the item I choose.

Lets say we have these as the 4 items:

Apples in range d135
Pears in range d136
Bananas in range d137
Grapes in range d138

If I select Pears I want it to replace the word pears with the word in range("F136") [Oranges]

I am new to using user forms so I cannot figure out how to do this.

Do you want to replace the values in the range D135:D138 with those in the corresponding range in column F?

Put this code in the Userform code module.

VBA Code:
Private Sub ComboBox1_Change()

  With Worksheets("Sheet1").Range("D135:D138").Cells(Me.ComboBox1.ListIndex + 1)
    .Value = .Offset(0, 2).Value
  End With
  
End Sub
 
Upvote 0
I had already gotten it to work with this code.

VBA Code:
Sheets("Sheet1").Range("D135:D138").Find(ComboBox1.List(ComboBox1.ListIndex)).Select
Selection = Sheets("Sheet1").Range("F136")

But thank you for your input.

Although if you know a way to where I do not have use ".Select" and then refer to my selection Id appreciate it if you could assist me with that.
 
Upvote 0
I had already gotten it to work with this code.

VBA Code:
Sheets("Sheet1").Range("D135:D138").Find(ComboBox1.List(ComboBox1.ListIndex)).Select
Selection = Sheets("Sheet1").Range("F136")

But thank you for your input.

Although if you know a way to where I do not have use ".Select" and then refer to my selection Id appreciate it if you could assist me with that.
You don't need to use Select.

My solution does not even need to find which cell to update because it already knows it from the order in the combo-box.
 
Upvote 0

Forum statistics

Threads
1,225,897
Messages
6,187,703
Members
453,435
Latest member
U4US

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