Trying to fill a combo box value to a cell in vba code

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I have created this code but it says error 438
Any ideas why??

VBA Code:
Sub BodyType()

Dim cmb As ComboBox
Dim wsDest As Worksheet
Dim i As Long, Range As Long

Set wsDest = ThisWorkbook.Worksheets("Job Card Master")
Set cmb = Body_And_Vehicle_Type_Form.Body_Type

For i = 0 To cmb.ListCount - 1

If cmb.Selected(i) Then

  wsDest.Range("E4") = cmb.List(i, 0)
  
    End If
    
  Next i

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You do not really need to loop through the values in the Combobox.

I use something like this:
Script runs when you select value in Combobox

VBA Code:
Private Sub ComboBox1_Change()
'Modified  4/15/2021  9:25:16 AM  EDT
Worksheets("Job Card Master").Range("E4").Value = ComboBox1.Value
End Sub
 
Upvote 0
Do want one value?
VBA Code:
If cmb.ListIndex <> -1 Then wsDest.Range("E4") = cmb.Value
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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