سلام بر اساتید بزرگوار
کدی می خوام که بزرگترین عدد رو از ستون a انتخاب و داخل یه کمبوباکس نشون بده
ممنون میشم
کدی می خوام که بزرگترین عدد رو از ستون a انتخاب و داخل یه کمبوباکس نشون بده
ممنون میشم
Private Sub ComboBox1_Change()
Dim ws As Worksheet
Dim LR, max As Long
Dim Cell As Range
Dim List As New Collection
Dim Item As Variant
Set ws = ActiveSheet
With ws
LR = .Cells(.Rows.Count, 1).End(xlUp).Row
ComboBox2.Clear
For Each Cell In .Range("A2:A" & LR)
With Cell
If .Text = ComboBox1.Value Then
On Error Resume Next
List.Add .Offset(0, 1).Text, CStr(.Offset(0, 1).Value)
On Error GoTo 0
End If
End With
Next Cell
max = 0
For Each Item In List
If Item >max Then
max = Item
End If
Next Item
End With
ComboBox2 = max + 1
End Sub
Private Sub ComboBox1_Change()
Dim ws As Worksheet
Dim LR, max As Long
Dim Cell As Range
Dim List As New Collection
Dim Item As Variant
Set ws = ActiveSheet
With ws
LR = .Cells(.Rows.Count, 1).End(xlUp).Row
ComboBox2.Clear
For Each Cell In .Range("A2:A" & LR)
With Cell
If .Text = ComboBox1.Value Then
On Error Resume Next
List.Add .Offset(0, 1).Text, CStr(.Offset(0, 1).Value)
On Error GoTo 0
End If
End With
Next Cell
max = 0
For Each Item In List
If Item >max Then
max = Item
End If
Next Item
End With
ComboBox2 = max + 1
End Sub
کامنت