Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default assign number value

Hi Tim:
This worksheet_change event procedure works for column K.
Adjust the isect range to whatever column(s) you need..

Private Sub Worksheet_Change(ByVal target As Range)
Dim isect As Range, c As Range
On Error GoTo Cleanup

Set isect = intersect(target, Range("K:K"))
If Not (isect Is Nothing) Then
Application.EnableEvents = False
For Each c In isect
If c.Value < "" Then
c.Value = 0
End If
Next c
End If

Cleanup:
Application.EnableEvents = True
End Sub

hth,
Jim Feaver

"Tim" wrote in message
...
I would like to make a column reject anything other than a number for the

column. If a word is put in there by a macro excel sees it is not a number
and replaces it with a 0 or blank.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default assign number value

Tim:
D'oh! I somehow managed to post the wrong copy
of the procedure. Here is the correct one,
along with a variation.

The use of isect enables it to assign a zero
no matter if one cell in the target row is
edited, copied/cut and pasted or if a range
of cells that includes or spans the target row
is copied/cut and pasted.
It also allows you to delete a zero or zeroes
in the target column either individually
or by selected any range that includes
or spans the target row.

If you prefer non-numeric values to become
blanks instead of zeroes, then use the second
procedure, which is just a slight variation of the
first one.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range, c As Range
On Error GoTo Cleanup

Set isect = Intersect(Target, Range("K:K"))
If Not (isect Is Nothing) Then
Application.EnableEvents = False
For Each c In isect

If c.Value < "" And _
Not (IsNumeric(c.Value)) Then
c.Value = 0
End If
Next c
End If

Cleanup:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range, c As Range
On Error GoTo Cleanup

Set isect = Intersect(Target, Range("K:K"))
If Not (isect Is Nothing) Then
Application.EnableEvents = False
For Each c In isect
If Not (IsNumeric(c.Value)) Then
c.Value = ""
End If
Next c
End If

Cleanup:
Application.EnableEvents = True
End Sub


hth,
Jim Feaver

The
"Jim Feaver" wrote in message
news:1ixUb.408600$ts4.158286@pd7tw3no...
Hi Tim:
This worksheet_change event procedure works for column K.
Adjust the isect range to whatever column(s) you need..

Private Sub Worksheet_Change(ByVal target As Range)
Dim isect As Range, c As Range
On Error GoTo Cleanup

Set isect = intersect(target, Range("K:K"))
If Not (isect Is Nothing) Then
Application.EnableEvents = False
For Each c In isect
If c.Value < "" Then
c.Value = 0
End If
Next c
End If

Cleanup:
Application.EnableEvents = True
End Sub

hth,
Jim Feaver

"Tim" wrote in message
...
I would like to make a column reject anything other than a number for

the
column. If a word is put in there by a macro excel sees it is not a number
and replaces it with a 0 or blank.




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
How do I assign a number to a name in another column? Michelle Excel Worksheet Functions 0 September 24th 09 10:16 PM
Can I assign a number to a name and use the name in a sum? beeno Excel Discussion (Misc queries) 1 July 11th 06 10:47 PM
Assign one number to a number range Sue New Users to Excel 1 October 6th 05 01:21 AM
Assign a number to a name Sukismomma Excel Worksheet Functions 4 March 3rd 05 07:49 PM
assign number value Bob Phillips[_6_] Excel Programming 0 February 5th 04 07:24 PM


All times are GMT +1. The time now is 12:36 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"