Data validataion with VBA/ Named Range

ogo

Board Regular
Joined
Mar 15, 2011
Messages
105
I was using the following code part for data validation
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$B$" & startRow & ":$B$" & endRow................

But the data and the drop down are in different sheets. So i had to try named range the variables startRow and endRow . But this is also not working.Is there any method take data from one sheet into drop down in other sheet .

Thanks,
Ogo
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You will need a singe name to return the rage, e.g.:
Code:
Sheet1.Range("B" & startRow & ":" & "B" & endRow).Name = "MyRange"

Then in Formula1 you merely refer to:
Code:
=MyRange
 
Upvote 0
Don't define the start row and end row as names. Define the actual range as a name and refer to that name.
 
Upvote 0
Hi there,

Maybe this will help?

Code:
ActiveWorkbook.Names.Add Name:="namedRange", RefersTo:="=Sheet2!$A$" & startRow & ":$A$" & endRow

    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=namedRange"
    End With
 
Upvote 0
I can define the range in a sheet but i'm not able it to use the data in the range to validate a cell in another sheet.
thanks,
ogo
 
Upvote 0
I can define the range in a sheet but i'm not able it to use the data in the range to validate a cell in another sheet.
thanks,
ogo
This is something that I have done hundreds of times. Describe exactly what you did, and what happened.
 
Upvote 0
What i have is two sheets. One sheet with data, and in a cell on the second sheet i have to display this data. So at first i tried to display it by creating comma separated string but this throwed some 1004 coz it exceeded 255 char. Now i'm trying to use a namedrange to do this...
thanks,
ogo
 
Upvote 0
ActiveWorkbook.Names.Add Name:="namedRange", RefersTo:="=Sheet2!$B$" & startRow & ":$B$" & endRow
Sheet5.Cells(iRow, iCol).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=namedRange"
End With


Is failing..and the following also,,


Sheet5.Cells(iRow, iCol).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Sheet2!$B$" & sMachine & ":$B$" & lMachine
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
'.ErrorTitle = ""
'.InputMessage = ""
'.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
 
Upvote 0
ActiveWorkbook.Names.Add Name:="namedRange", RefersTo:="=Sheet2!$B$" & startRow & ":$B$" & endRow
Sheet5.Cells(iRow, iCol).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=namedRange"
End With

Is failing..and the following also,,
When you say this fails, specifically what error do you get, and where in the code does it break?

After adding the named range, have you gone back into the name manager to confirm that it is there?

Can you post more of the code please, because I can't see what startRow, endRow, iRow and iCol are, or where they are loaded.
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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