Use universal indirect function with Data Validation list in VBA Excel

I have downloaded a forum for VBA which lets you search in a drop-down list. It works great until it encounters a dependent drop-down list(a drop-down that looks at an Indirect function.) It only displays the function and not the referred cell.

As I am quite new to VBA I had some troubles with adding the indirect function. There is a youtube video of the guy who wrote the code(https://www.youtube.com/watch?v=HXCwvRzRJZc) and I have tried to look over it and create another condition where it shows the value of the indirect drop-down list. But unfortunately I have failed numerous times. I understand that the Range and the validation of an active cell plays a part of it I just cannot puzzle it together.

The whole forum code as well as the range validation.

Sub Refresh_List()

Dim arr() As String
Dim i As Integer
Me.ListBox1.Clear
Dim rng As Range
Dim cel As Range

If IsValidation(ActiveCell) = True Then


If Valid_Range(ActiveCell.Validation.Formula1) = True Then
    Set rng = Range(Replace(ActiveCell.Validation.Formula1, "=", ""))


    For Each cel In rng
            If Me.TextBox1.Value = "" Then
            Me.ListBox1.AddItem cel.Value
        Else
        
            If VBA.InStr(UCase(cel.Value), UCase(Me.TextBox1.Value)) > 0 Then
                Me.ListBox1.AddItem cel.Value
            End If
        End If
Next
    

Else



arr = VBA.Split(ActiveCell.Validation.Formula1, ",")

For i = LBound(arr) To UBound(arr)
        If Me.TextBox1.Value = "" Then
            Me.ListBox1.AddItem arr(i)
        Else
            If VBA.InStr(UCase(arr(i)), UCase(Me.TextBox1.Value)) > 0 Then
                Me.ListBox1.AddItem arr(i)
            End If
        End If
Next i
End If
End If
On Error Resume Next
Me.ListBox1.ListIndex = 0
On Error GoTo 0

End Sub

Private Sub CommandButton1_Click()
    Me.CommandButton2.Visible = True
    Me.CommandButton1.Visible = False
    Me.Height = 256
    
End Sub

Private Sub CommandButton2_Click()
    Me.CommandButton1.Visible = True
    Me.CommandButton2.Visible = False
    Me.Height = 164

End Sub


Private Sub ListBox1_Click()

End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Call Update_Data

End Sub

Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then
        Call Update_Data
        End If
End Sub


Private Sub TextBox1_Change()
Call Refresh_List
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

    If KeyCode = 13 Then
        Call Update_Data
        End If
        

End Sub

Private Sub UserForm_Activate()
Call Refresh_List
End Sub

Sub Refresh_List()

Dim arr() As String
Dim i As Integer
Me.ListBox1.Clear
Dim rng As Range
Dim cel As Range

If IsValidation(ActiveCell) = True Then


If Valid_Range(ActiveCell.Validation.Formula1) = True Then
    Set rng = Range(Replace(ActiveCell.Validation.Formula1, "=", ""))


    For Each cel In rng
            If Me.TextBox1.Value = "" Then
            Me.ListBox1.AddItem cel.Value
        Else
        
            If VBA.InStr(UCase(cel.Value), UCase(Me.TextBox1.Value)) > 0 Then
                Me.ListBox1.AddItem cel.Value
            End If
        End If
Next
    

Else



arr = VBA.Split(ActiveCell.Validation.Formula1, ",")

For i = LBound(arr) To UBound(arr)
        If Me.TextBox1.Value = "" Then
            Me.ListBox1.AddItem arr(i)
        Else
            If VBA.InStr(UCase(arr(i)), UCase(Me.TextBox1.Value)) > 0 Then
                Me.ListBox1.AddItem arr(i)
            End If
        End If
Next i
End If
End If
On Error Resume Next
Me.ListBox1.ListIndex = 0
On Error GoTo 0

End Sub

Function Valid_Range(str As String) As Boolean
Dim rng As Range

On Error Resume Next
Set rng = Range(Replace(str, "=", ""))
On Error GoTo 0

If rng Is Nothing Then
    Valid_Range = False
Else
    Valid_Range = True
End If



End Function



Function IsValidation(rng As Range) As Boolean

Dim dvtype As Integer

On Error Resume Next
dvtype = rng.Validation.Type
On Error GoTo 0

If dvtype = 3 Then

    IsValidation = True
    
Else

    IsValidation = False

End If


End Function



Sub Update_Data()

ActiveCell.Value = Me.ListBox1.Value
If Me.OptionButton1.Value = True Then
    ActiveCell.Offset(1, 0).Select
    
    If Me.TextBox1.Value <> "" Then
        Me.TextBox1.Value = ""
    Else
        Call Refresh_List
    End If
    
    If Me.ListBox1.ListCount = 0 Then Me.Hide
    
    
End If

If Me.OptionButton2.Value = True Then
    ActiveCell.Offset(0, 1).Select
    
    If Me.TextBox1.Value <> "" Then
        Me.TextBox1.Value = ""
    Else
        Call Refresh_List
    End If
    
    If Me.ListBox1.ListCount = 0 Then Me.Hide
    
    
    
End If

If Me.OptionButton3.Value = True Then
     Me.TextBox1.Value = ""
    
    
End If

If Me.OptionButton4.Value = True Then
     Me.TextBox1.Value = ""
     Unload Me
    
End If

End Sub

Private Sub CommandButton3_Click()
    Me.TextBox1.Value = ""
    Unload Me
End Sub


New contributor

Liam Mullins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật