Hello I get the Names and its range displayed in combobox with below code, want to check if the Name typed in textbox1 should however match the name in combobox with msgbox displayed "Exists" and its range displayed in another Textbox eg. Textbox2
I am unable to get the Range Address in Textbox2
The List displayed in ComboBox1 as follows ie with Name and Range
596501 A2:AI6
102603 A7:AI9
NIM-K-102 556304 A10:AI15 ' The Name here is different with space in between
Thanks NimishK
I am unable to get the Range Address in Textbox2
The List displayed in ComboBox1 as follows ie with Name and Range
596501 A2:AI6
102603 A7:AI9
NIM-K-102 556304 A10:AI15 ' The Name here is different with space in between
Code:
Sub GetNames()
Dim Ray() As String
Dim c As Range, LastA As Range
Dim rws As Long, k As Long
Set LastA = Range("A" & Range("AC" & Rows.Count).End(xlUp).Row)
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants)
rws = 1
If IsEmpty(c.Offset(1).Value) And c.Address <> LastA.Address Then rws = rws + Range(c, LastA).SpecialCells(xlBlanks).Areas(1).Rows.Count
k = k + 1
ReDim Preserve Ray(1 To k)
Ray(k) = c.Value & " " & c.Resize(rws, 29).Address(0, 0)
Next c
ComboBox1.List = Ray
End Sub
Private Sub cmdBtnGetNames_Click()
Dim i as integer
Call GetNames
For i = 0 To ComboBox1.ListCount - 1
If ComboBox1.List(i) =Textbox1.Text Then
MsgBox ComboBox1.List(i) & " Exists"
Textbox2.text = Split(ComboBox1.List(i) , " ")(1)
End If
Exit For
Next i
End Sub
Last edited: