View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Earl Kiosterud Earl Kiosterud is offline
external usenet poster
 
Posts: 611
Default Enter number in cell and have it divide by 4

Chey,

You have to say more than "did not work."

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("C25")) Is Nothing Then
On Error GoTo errr
If IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target = Target / 4
Application.EnableEvents = True
End If
End If

If Not Intersect(Target, Range("C26")) Is Nothing Then
On Error GoTo errr
If IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target = Target / 8
Application.EnableEvents = True
End If
End If

End
errr:
Application.EnableEvents = True
MsgBox "Error: " & Err.Description
End Sub
--
Regards from Virginia Beach,

Earl Kiosterud
www.smokeylake.com


-----------------------------------------------------------------------
"Chey" wrote in message
...
I put it in the visual basic is that right?

If so It did not work

I need to narrow it down to exactly a colum and a row.
example C25

So when I type 12 in C25 it changes it to 3
in C26 it needs to divide by 8.

Thanks for your time.

Cheyenne

"Earl Kiosterud" wrote:

Chey,

This will require an even-driven (Worksheet_Change) macro. You'll have to put in in the
workbook. Here's one that will divide anything in column B (column #2):

Private Sub Worksheet_Change(ByVal Target As Range)
Const ColumnNumber = 2
If Not Intersect(Target, Cells(1, ColumnNumber).EntireColumn) Is Nothing Then
On Error GoTo errr
If IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target = Target / 4
Application.EnableEvents = True
End If
End If
End
errr:
Application.EnableEvents = True
MsgBox "Error: " & Err.Description
End Sub

It goes in the Sheet module for the sheet involved.

Or you can put your original value in, and have another cell with a formula that produces
the result you want:

=A2/4
--
Regards from Virginia Beach,

Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
"Chey" wrote in message
...
I have a cell that when I type the number for example 12 I want it to return 3
So the Number I type in divided by 4.
I have some other cells I am going to do with the number 8 and so on.
Thanks
Cheyenne