Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Code for an entire column

I would like this code to validate the data for all of column F - any
suggestions?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$F$4" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, "Data Validation"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Code for an entire column

Try this:
If Not Intersect(Target, Range("F:F")) Is Nothing Then
Instead of:
If Target.Address = "$F$4" Then

--
Charles Chickering

"A good example is twice the value of good advice."


"Kimberly" wrote:

I would like this code to validate the data for all of column F - any
suggestions?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$F$4" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, "Data Validation"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Code for an entire column

Thank you very much!

"Charles Chickering" wrote:

Try this:
If Not Intersect(Target, Range("F:F")) Is Nothing Then
Instead of:
If Target.Address = "$F$4" Then

--
Charles Chickering

"A good example is twice the value of good advice."


"Kimberly" wrote:

I would like this code to validate the data for all of column F - any
suggestions?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$F$4" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, "Data Validation"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Code for an entire column

Change

If Target.Address = "$F$4" Then

to this.............

If Not Application.Intersect(Target, Columns("F:F")) Is Nothing Then


Gord Dibben MS Excel MVP

On Wed, 7 Feb 2007 13:00:01 -0800, Kimberly
wrote:

I would like this code to validate the data for all of column F - any
suggestions?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$F$4" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, "Data Validation"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
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
If data in one column, take date, add 2 days, and turn the entire column a color... [email protected] Excel Discussion (Misc queries) 6 August 24th 06 03:58 AM
my column is sorted in two sections. How do I sort entire column? Elcar Excel Discussion (Misc queries) 0 February 13th 06 08:41 PM
my column is sorted in two sections. How do I sort entire column? Bob Umlas, Excel MVP Excel Discussion (Misc queries) 0 February 13th 06 08:41 PM
Find Column heading and then Delete entire column Kobayashi[_58_] Excel Programming 4 October 17th 05 09:09 PM
Code for deleting entire row gregork Excel Programming 2 July 4th 04 12:13 PM


All times are GMT +1. The time now is 09:53 PM.

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"