Data validation with

Paul21

New Member
Joined
Mar 17, 2018
Messages
17
Hallo,

I am Paul and I am trying to get drop list (data validation) in every line up to the last not empty line using drop list values from the same line.
For example - droplist in K2 with values from B2 to I2. This should be aplied to all not empty lines.

This is my code wich let me have drop lists up to the last non empty line (Range("A2", Range("A2").End(xlDown)).Validation) although I would like to have this in collumn K and not A.
The most tricky part is that I do not find a way how to modifu this (Formula1:="=Sheet2!B3:I3") in order to update/iterate for every line down to the last non empty cell.
Would be very gratefull for help :).

VBA Code:
Sub droplist()

'replace "J2" with the cell you want to insert the drop down list
With Range("A2", Range("A2").End(xlDown)).Validation
.Delete
'replace "=A1:A6" with the range the data is in.
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Sheet2!B3:I3"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = False
End With
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
To put the DV in col K use
VBA Code:
With Range("K2:K" & Range("A2").End(xlDown).Row).Validation
Assuming the DV should look at the values in that row, the formula should be
=Sheet2!B2:I2
 
Upvote 0
hi, Fluff, it works -thx. By the wat how do you explain this Range&Range ?
"K2:K" & Range("A2").End(xlDown)
 
Upvote 0
Its the range from K2 downwards until the first blank cell in col A.
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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