Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default using a macro to apply data validation to several cells

hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default using a macro to apply data validation to several cells

Pete,

Yes, I have an idea: you need to pass a valid range reference to the formula1 property of the
validation object.
For example:

Dim rowcount As Integer
rowcount = 3

With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & Cells(241, 1).Resize(rowcount, 1).Address
End With

But I have no idea what you are trying to do with the Match * formula. Explain the logic of your
list selection, and then we'll go from there. Until then, I'm stuck .

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default using a macro to apply data validation to several cells

hi bernie

the formula im trying to apply gives a dynamic range so that you can add to
the range without re-writing the reference

http://www.cpearson.com/excel/named.htm

the resize option is a new one to me that ill remember but isnt as flexible.
i have used "advanced filter unique records" to create the lists im refering
to so i dont know in advance how many rows each will have. currenly the lists
a accross the spreadsheet whilst the cells im validating are down a column
making copying the formula imposible. im going to re-arrange the lists so
they are in the same plane

hope this helps you understand what im am trying to do

"Bernie Deitrick" wrote:

Pete,

Yes, I have an idea: you need to pass a valid range reference to the formula1 property of the
validation object.
For example:

Dim rowcount As Integer
rowcount = 3

With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & Cells(241, 1).Resize(rowcount, 1).Address
End With

But I have no idea what you are trying to do with the Match * formula. Explain the logic of your
list selection, and then we'll go from there. Until then, I'm stuck .

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default using a macro to apply data validation to several cells

Pete,

Ah, OK.

Dim myCell As Range

For Each myCell In Selection
With myCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=OFFSET(" & Cells(241, myCell.Column).Address & ",0,0,COUNTA(" & _
Cells(241, myCell.Column).Resize(1000).Address & "),1)"
End With

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi bernie

the formula im trying to apply gives a dynamic range so that you can add to
the range without re-writing the reference

http://www.cpearson.com/excel/named.htm

the resize option is a new one to me that ill remember but isnt as flexible.
i have used "advanced filter unique records" to create the lists im refering
to so i dont know in advance how many rows each will have. currenly the lists
a accross the spreadsheet whilst the cells im validating are down a column
making copying the formula imposible. im going to re-arrange the lists so
they are in the same plane

hope this helps you understand what im am trying to do

"Bernie Deitrick" wrote:

Pete,

Yes, I have an idea: you need to pass a valid range reference to the formula1 property of the
validation object.
For example:

Dim rowcount As Integer
rowcount = 3

With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & Cells(241, 1).Resize(rowcount, 1).Address
End With

But I have no idea what you are trying to do with the Match * formula. Explain the logic of
your
list selection, and then we'll go from there. Until then, I'm stuck .

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default using a macro to apply data validation to several cells

Pete,

I hit send before I finished this - someone came into my office, and I sent it out without
remembering to add:

The code is written for having the data validation list at the bottom of the appliacable column,
starting in row 241, extending for up to 1000 values.

Select all the cells that you want to apply CF to, and run the macro.

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Pete,

Ah, OK.

Dim myCell As Range

For Each myCell In Selection
With myCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=OFFSET(" & Cells(241, myCell.Column).Address & ",0,0,COUNTA(" & _
Cells(241, myCell.Column).Resize(1000).Address & "),1)"
End With

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi bernie

the formula im trying to apply gives a dynamic range so that you can add to
the range without re-writing the reference

http://www.cpearson.com/excel/named.htm

the resize option is a new one to me that ill remember but isnt as flexible.
i have used "advanced filter unique records" to create the lists im refering
to so i dont know in advance how many rows each will have. currenly the lists
a accross the spreadsheet whilst the cells im validating are down a column
making copying the formula imposible. im going to re-arrange the lists so
they are in the same plane

hope this helps you understand what im am trying to do

"Bernie Deitrick" wrote:

Pete,

Yes, I have an idea: you need to pass a valid range reference to the formula1 property of the
validation object.
For example:

Dim rowcount As Integer
rowcount = 3

With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & Cells(241, 1).Resize(rowcount, 1).Address
End With

But I have no idea what you are trying to do with the Match * formula. Explain the logic of
your
list selection, and then we'll go from there. Until then, I'm stuck .

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default using a macro to apply data validation to several cells

hi bernie

i think i have solved my problem by placing my lists in rows rather than
column. this allowed me to copy the data validation from one cell to another
and the cell refs changed correctly.

thanks for taking the time to help ill study your example to further my
knowledge

regards

pete

"Bernie Deitrick" wrote:

Pete,

I hit send before I finished this - someone came into my office, and I sent it out without
remembering to add:

The code is written for having the data validation list at the bottom of the appliacable column,
starting in row 241, extending for up to 1000 values.

Select all the cells that you want to apply CF to, and run the macro.

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Pete,

Ah, OK.

Dim myCell As Range

For Each myCell In Selection
With myCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=OFFSET(" & Cells(241, myCell.Column).Address & ",0,0,COUNTA(" & _
Cells(241, myCell.Column).Resize(1000).Address & "),1)"
End With

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi bernie

the formula im trying to apply gives a dynamic range so that you can add to
the range without re-writing the reference

http://www.cpearson.com/excel/named.htm

the resize option is a new one to me that ill remember but isnt as flexible.
i have used "advanced filter unique records" to create the lists im refering
to so i dont know in advance how many rows each will have. currenly the lists
a accross the spreadsheet whilst the cells im validating are down a column
making copying the formula imposible. im going to re-arrange the lists so
they are in the same plane

hope this helps you understand what im am trying to do

"Bernie Deitrick" wrote:

Pete,

Yes, I have an idea: you need to pass a valid range reference to the formula1 property of the
validation object.
For example:

Dim rowcount As Integer
rowcount = 3

With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & Cells(241, 1).Resize(rowcount, 1).Address
End With

But I have no idea what you are trying to do with the Match * formula. Explain the logic of
your
list selection, and then we'll go from there. Until then, I'm stuck .

HTH,
Bernie
MS Excel MVP


"pete the greek" wrote in message
...
hi folks

i would like to use a macro to add data validation to several cells where
the source data for each is in a different list (200+)

i have the code below from recording

Sub Macro6()
'

'




With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=offset(a241,0,0,match(""*"",A:A,-1),1)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub

what i need to be able to change is the cell and column references in the
formula =offset(a241,0,0,match(""*"",A:A,-1),1)"

i have tried building this into a a string variable and substituting this in
the code

string_variable = "=offset(" & col_letter & "241,0,0,match(""*""," &
col_letter & ":" & col_letter & ",-1_1)"

Formula1:=string_variable

to no avail..

i have also tried building the string in situ


any ideas











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007-programming macros that apply to data validation Derek Megyesi New Users to Excel 1 January 31st 10 10:11 PM
How to use formula to decide when to apply TIME data validation Barbara T Excel Worksheet Functions 3 November 3rd 09 06:34 PM
Apply Data Validation List only IF . . . KUMPFfrog Excel Worksheet Functions 2 April 2nd 08 09:41 PM
macro Excel problem link cells with Data-Validation option [email protected] Excel Discussion (Misc queries) 3 March 26th 08 09:20 AM
How can i apply the validation on the cell with invalid data. Shinya Koizumi Excel Programming 1 February 2nd 06 08:52 PM


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"