Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating in VBA


Hi

I want to only allow a list of names to be entered into column D. I
copy over the cells so the "excel, data, validation, list" doesn't
work. How do I create a code that only allows this list in the said
column?

CC


--
Casey C
------------------------------------------------------------------------
Casey C's Profile: http://www.excelforum.com/member.php...o&userid=29090
View this thread: http://www.excelforum.com/showthread...hreadid=488147

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Validating in VBA

Lets put the list of valid entries in column B - about 100 valid names. Tehn:


Sub Macro1()
Dim i As Long
For i = 65536 To 1 Step -1
If IsEmpty(Cells(i, 4).Value) Then
Else
v = Cells(i, 4)
k = 0
For j = 1 To 100
If Cells(j, 2).Value = v Then
k = 1
End If
Next
If k = 0 Then
Cells(i, 4).Delete Shift:=xlUp
End If
End If
Next
End Sub

will scrub column D and remove all entries not appearing in column B.

--
Gary's Student


"Casey C" wrote:


Hi

I want to only allow a list of names to be entered into column D. I
copy over the cells so the "excel, data, validation, list" doesn't
work. How do I create a code that only allows this list in the said
column?

CC


--
Casey C
------------------------------------------------------------------------
Casey C's Profile: http://www.excelforum.com/member.php...o&userid=29090
View this thread: http://www.excelforum.com/showthread...hreadid=488147


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Validating in VBA

I'd use another column that shows a warning message if it's invalid:

=if(d2="","",if(isnumber(match(d2,sheet2!a:a,0))," ","Not a match"))

And format that cell in big bold red letters. Then drag it down the column.

Casey C wrote:

Hi

I want to only allow a list of names to be entered into column D. I
copy over the cells so the "excel, data, validation, list" doesn't
work. How do I create a code that only allows this list in the said
column?

CC

--
Casey C
------------------------------------------------------------------------
Casey C's Profile: http://www.excelforum.com/member.php...o&userid=29090
View this thread: http://www.excelforum.com/showthread...hreadid=488147


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating in VBA


Another way, via Worksheet_Change Event:

Assuming your list is in range B1:B20 and your working range is Column
D

Private Sub Worksheet_Change(ByVal c As Excel.Range)
If Intersect(c, Range("d1:d20")) Is Nothing Then Exit Sub
If Not Range("b1:b5").Find(c) Is Nothing Then
c = c.Value
Else
c.ClearContents
End If
End Sub


David


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=488147

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating in VBA


Correction: (as bolded)

Another way, via Worksheet_Change Event:

Assuming your list is in range *B1:B5* and your working range is
*D1:D20*

Private Sub Worksheet_Change(ByVal c As Excel.Range)
If Intersect(c, Range("d1:d20")) Is Nothing Then Exit Sub
If Not Range("b1:b5").Find(c) Is Nothing Then
c = c.Value
Else
c.ClearContents
End If
End Sub


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=488147



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Validating in VBA

Casey:

try something like this:

'----------------------------------------------------------------------
'TARGET is the cell you want to add validation to
'
'LISTRANGE would be the cells in column CC _
that have the data you want your TARGET to_
be limited to.
'----------------------------------------------------------------------

Sub AddValidation(Target As Range, ListRange As Range)

Dim strAddress As String

strAddress = "=" & ListRange.Address
With Target.Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=strAddress
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True

End With

End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Validating in VBA

Casey: Try something like this...

'-----------------------------------------------------
'
'TARGET is the cell you want to add validation to
'
'LISTRANGE are the cells in column CC that contain _
the list of names that you want the TARGET _
to be limited to
'
'-----------------------------------------------------
Sub AddValidation(Target As Range, ListRange As Range)

Dim strAddress As String

strAddress = "=" & ListRange.Address
With Target.Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=strAddress

.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True

End With

End Sub

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Validating in VBA

Casey, try this:

'-----------------------------------------------------
'
'TARGET is the cell you want to add validation to
'
'LISTRANGE are the cells in column CC that contain _
the list of names that you want the TARGET _
to be limited to
'
'-----------------------------------------------------
Sub AddValidation(Target As Range, ListRange As Range)

Dim strAddress As String

strAddress = "=" & ListRange.Address
With Target.Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=strAddress
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With

End Sub

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
validating Philashley Excel Discussion (Misc queries) 2 March 13th 08 03:54 PM
validating outside of Excel BorisS Excel Discussion (Misc queries) 0 February 22nd 07 04:12 PM
validating Ayesha Excel Worksheet Functions 2 April 26th 06 02:56 PM
Validating Sdbenn90 Excel Discussion (Misc queries) 0 March 27th 06 12:05 AM
Validating Dates Luis Verme Excel Programming 22 July 10th 05 11:41 AM


All times are GMT +1. The time now is 11:22 AM.

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

About Us

"It's about Microsoft Excel"