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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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