VBA Data Validation List and Address

RenewableEE

New Member
Joined
Mar 22, 2016
Messages
1
The code below is used to go through a range of values looking for the first cell that is < 0. It then inputs a Data Validation list, Lengths_7000. The cell is given a default value, but I want to capture the address of where the validation list was entered to be used in the code later. Any ideas?

The latter case statements have yet to be written, so please ignore those.

Code:
Sub Allocation()

    Dim cableSize As String
    cableSize = ThisWorkbook.Sheets("Cable Management").range("C3")
    
    Select Case cableSize
        
        Case "1/0"
            With range("G3").Validation                                                                     'Call data validation list to Cell G3
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
                Operator:=xlBetween, Formula1:="=Lengths_7000"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
            
            Dim cnt As Long
            Dim colm As Long
            Dim defaultValue As Long
            cnt = 4                                                                                         'The fourth row
            colm = 8                                                                                        'Row H
            defaultValue = 7000                                                                             'default value set at 7000
            Do While (Not Cells(cnt, colm).Value <= 0) And (cnt < 500)                                      'until either a cell is < 0 or we are at row 500. This means we have checked row 499.
                cnt = cnt + 1                                                                               'Increasing the row
                If Cells(cnt, colm) <= 0 Then                                                               'look for cell that is < 0
                    With Cells(cnt, colm - 1).Validation                                                    'Insert data validation list into cell one column before cell < 0
                        .Delete
                        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
                        Operator:=xlBetween, Formula1:="=Lengths_7000"
                        .IgnoreBlank = True
                        .InCellDropdown = True
                        .InputTitle = ""
                        .ErrorTitle = ""
                        .InputMessage = ""
                        .ErrorMessage = ""
                        .ShowInput = True
                        .ShowError = True
                    End With
                    ThisWorkbook.Sheets("Cable Management").Cells(cnt, colm - 1).Value = defaultValue       'give cell with validation list default value
                End If
            Loop
            
        Case "1"
        
        Case "2"
        
        Case "3"
        
        Case "4"
        
        Case Else
            MsgBox "Please make the appropriate selection."
    End Select
End Sub
 

Forum statistics

Threads
1,085,989
Messages
5,387,127
Members
402,045
Latest member
Hidalgo

Some videos you may like

This Week's Hot Topics

Top