Combobox VBA

Rvittur

New Member
Joined
Mar 8, 2023
Messages
20
Office Version
  1. 365
Platform
  1. Windows
I want to find and select a cell in another workbook via VBA based on a text value picked from a userform combobox. The target value will be a text value in a column which will NOT be sorted. So if Suit Down box has a selected name in it and Start Change has a time in it. In other workbook, find Suit Down name in column D and change Start time in column C to what the time is in the Start Change box is. Is that doable at all? I also attached pictures and one is my working code for the other boxes. In the code pic you can see where I was try a code out but wasn't working for me.
Shot of Code.jpg

filled example.jpg
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
According to these 2 conditions:
So if Suit Down box has a selected name in it and Start Change has a time in it.
You should have something like this:
Rich (BB code):
If .cmdSuitDown.Value <> "" And .cmdTSC.Value <> "" Then


---------------------
According with this:
find Suit Down name in column D and change Start time in column C
You should have something like this:
Rich (BB code):
Set f = ws2.Range("D:D").Find(.cmdSuitDown, , xlValues, xlWhole, , , False)

-------------------
Then try this:
VBA Code:
Private Sub CommandButton1_Click()
  Dim wb2 As Workbook
  Dim ws2 As Worksheet
  Dim f As Range
  
  Set wb2 = Workbooks("another")      'Fit with your book name
  Set ws2 = wb2.Sheets("Roadmap")     'Fit with your sheet name
  
  With UserForm1
    If .cmdSuitDown.Value <> "" And .cmdTSC.Value <> "" Then
      Set f = ws2.Range("D:D").Find(.cmdSuitDown, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        ws2.Range("C" & f.Row).Value = .cmdTSC.Value
        MsgBox "Updated value"
      Else
        MsgBox "That value does not exist"
      End If
    End If
  End With
End Sub

Note Code Tag:
In future please use code tags when posting code, instead of a picture.
How to Post Your VBA Code it makes your code easier to read and copy and it also maintains VBA formatting.

I hope to hear from you soon.
Respectfully
Dante Amor
----- --
 
Upvote 0
Solution
According to these 2 conditions:

You should have something like this:
Rich (BB code):
If .cmdSuitDown.Value <> "" And .cmdTSC.Value <> "" Then


---------------------
According with this:

You should have something like this:
Rich (BB code):
Set f = ws2.Range("D:D").Find(.cmdSuitDown, , xlValues, xlWhole, , , False)

-------------------
Then try this:
VBA Code:
Private Sub CommandButton1_Click()
  Dim wb2 As Workbook
  Dim ws2 As Worksheet
  Dim f As Range
 
  Set wb2 = Workbooks("another")      'Fit with your book name
  Set ws2 = wb2.Sheets("Roadmap")     'Fit with your sheet name
 
  With UserForm1
    If .cmdSuitDown.Value <> "" And .cmdTSC.Value <> "" Then
      Set f = ws2.Range("D:D").Find(.cmdSuitDown, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        ws2.Range("C" & f.Row).Value = .cmdTSC.Value
        MsgBox "Updated value"
      Else
        MsgBox "That value does not exist"
      End If
    End If
  End With
End Sub

Note Code Tag:
In future please use code tags when posting code, instead of a picture.
How to Post Your VBA Code it makes your code easier to read and copy and it also maintains VBA formatting.

I hope to hear from you soon.
Respectfully
Dante Amor
----- --
omg thank you so much for this. It worked! now i just need to modify it for the rest of the code.
 
Upvote 1

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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