Need help in VBA coding for the below

michaelroshan

New Member
Joined
Jun 27, 2020
Messages
16
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I am looking for the code for the attached userform!,
Item Code and Item Name are drop down lists from a Range,
i am looking to use the Item Name drop down to change the value of the item code when i change the value of Item Name.! I have already got the codeing done to change the Item name and Unit to change when i change the value of the Item Code.
How do i get both of them done? ... the Code is below

Rich (BB code):
Private Sub UserForm_Initialize()
    
 Set sh = Sheets("2021")

With MonthBox2
.AddItem "JAN"
.AddItem "FEB"
.AddItem "MAR"
.AddItem "APR"
.AddItem "MAY"
.AddItem "JUN"
.AddItem "JUL"
.AddItem "AUG"
.AddItem "SEP"
.AddItem "OCT"
.AddItem "NOV"
.AddItem "DEC"
End With

With CCBox2
.AddItem ""
.AddItem "MAZ"
.AddItem "RHQ"
.AddItem "RCG"
.AddItem "RES"
.AddItem "CC"
End With
  'Next
  ItemBox2.List = sh.Range("B5", sh.Range("B" & Rows.Count).End(3)).Value
  NameBox2.List = sh.Range("C5", sh.Range("C" & Rows.Count).End(3)).Value

End Sub


Private Sub NameBox2_Change()
    RunObject Me.NameBox2
End Sub

Private Sub ItemBox2_Change()
    RunObject Me.ItemBox2
End Sub

Private Sub CCBox2_Change()
    RunObject Me.CCBox2
End Sub

Private Sub MonthBox2_Change()
    RunObject Me.MonthBox2
End Sub



Private Sub RunObject(object)
Dim sr As String, nm As String
Dim lookupRange As Range
'Dim ItemBox As Variant
'Dim MonthBox As Variant
'Dim CCBox As Variant
Set lookupRange = Worksheets("2021").Range("$B$5:$CWI$7000")
'If Me.ItemBox2.Value = "" Then
'MsgBox "Please Enter Item Code to Update!!!", vbExclamation, "Item Code!"
'Exit Sub
'End If
sr = Me.ItemBox2.Value
nm = Me.NameBox2.Value

On Error Resume Next

Me.ItemBox2.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 1, 0)
Me.NameBox2.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 2, 0)
Me.UnitBox2.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 3, 0)
Me.masterBalanceLabel = Application.WorksheetFunction.VLookup(sr, lookupRange, 201, 0)
 

Attachments

  • xxxx.png
    xxxx.png
    17.4 KB · Views: 4
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
also it would be awesome if i can add a photo as well to he same selection! i have an iventory list of over 1500 items.
This userform looks like this
 

Attachments

  • xxxx.png
    xxxx.png
    40 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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