cbobox items to loop in range

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
Not sure how to go about this. I populated combobox15 with some items in some code that isn't posted. I'd like the user to be able to make a group edit to those items in the cbobox15. Because the items are unique; I thought I would run each cbobox item against the range and change accordingly as written below. The only thing I could use some help with, would be how I address comparing the combobox items. Pretty sure I'm handling it wrong and could use some direction.



Code:
Private Sub CommandButton37_Click()
Dim param As Worksheet
    Set param = Worksheets("control")
Dim ques1 As String
    ques1 = ""
    ques1 = Application.InputBox("Enter character(s) to be removed from data")
Dim ques2 As String
    ques2 = ""
    ques2 = Application.InputBox("Enter character(s) to replace with")
Dim cell As Range
[COLOR=Magenta]Dim items As ComboBox.Item[/COLOR]
Dim iTe As Worksheet
    Set iTe = Worksheets(ComboBox2.Value)

If ques1 = "False" Then Exit Sub
If MsgBox("Are you sure you want to replace " & ques1 & " with " & ques2, vbYesNo) = vbNo Then
    'no
Else:
    For Each [COLOR=Magenta]items In ComboBox15.List[/COLOR]
        For Each cell In iTe.Range(ComboBox3.Value & TextBox1.Value & ":" & ComboBox3.Value & TextBox2.Value).Cells
            If iTe.Range(ComboBox11.Value & cell.Row).Value <> 2 Then GoTo lynnloop
                If cell.Text <>[COLOR=Magenta] items[/COLOR] Then GoTo lynnloop
                    cell.Value = Replace(cell.Value, ques1, ques2)
                    cell.Value = Trim(cell.Value)
                    iTe.Range(ComboBox11.Value & cell.Row).Value = ""
lynnloop:
        Next cell
    [COLOR=Magenta]Next Item[/COLOR]
End If
End Sub
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
ok....getting closer. I tried the below code but it only works for the first item in the combobox15. It doesn't do it for all items in the combobox15 like it should.

Code:
Private Sub CommandButton37_Click()
Dim param As Worksheet
    Set param = Worksheets("control")
Dim ques1 As String
    ques1 = ""
    ques1 = Application.InputBox("Enter character(s)to be removed from data")
Dim ques2 As String
    ques2 = ""
    ques2 = Application.InputBox("Enter character(s)to replace with")
Dim cell As Range
[COLOR=Magenta]Dim iCBo As Integer[/COLOR]
Dim iTe As Worksheet
    Set iTe = Worksheets(ComboBox2.Value)

If ques1 = "False" Then Exit Sub
If MsgBox("Are you sure you want to replace " & ques1 & " with " & ques2, vbYesNo) = vbNo Then
    'no
Else:
    [COLOR=Magenta]For iCBo = 0 To ComboBox15.ListCount - 1[/COLOR]
        For Each cell In iTe.Range(ComboBox3.Value & TextBox1.Value & ":" & ComboBox3.Value & TextBox2.Value).Cells
            If iTe.Range(ComboBox11.Value & cell.Row).Value <> 2 Then GoTo lynnloop
                If cell.Text <> [COLOR=Magenta]ComboBox15.Text [/COLOR]Then GoTo lynnloop
                    cell.Value = Replace(cell.Value, ques1, ques2)
                    cell.Value = Trim(cell.Value)
                    iTe.Range(ComboBox11.Value & cell.Row).Value = ""
lynnloop:
        Next cell
   [COLOR=Magenta] Next iCBo[/COLOR]
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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