auto calculation on the same cell without a helper cell?

  • Thread starter Thread starter cpliu
  • Start date Start date
C

cpliu

I'd like the number I enters automatically divided by 1024 without a
helper cell to show the result at the same cell I enters. Is it
possible to do that?

Thanks,
 
This macro will do that for any cell on your sheet. Post back if you want
to limit this action to a specific range of cells. Right-click on the sheet
tab and select View Code. Paste this macro into that module. "X" out of
the module to return to your sheet/ HTH Otto
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If IsEmpty(Target) Then Exit Sub
Target = Target / 1024
End Sub
 
With event code........yes.

Private Sub Worksheet_Change(ByVal Target As Range)
Const myRange As String = "A1:A10"
On Error GoTo endit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(myRange)) Is Nothing Then
With Target
.Value = .Value / 1024
End With
End If
endit:
Application.EnableEvents = True
End Sub

This is sheet efent code. Right-click on the sheet tab and "View Code"

Copy/paste the code into that sheet module.

Edit to suit for range.

Alt + q to return to Excel.

Start entering numbers which will be divided by 1024 when you hit Enter key.


Gord Dibben MS Excel MVP
 
Right click sheet tab>view code>insert this

Private Sub Worksheet_Change(ByVal Target As Range)
'restricts to a1 modify to suit
if target.address<>range("a1").address then exit sub

Application.EnableEvents = False
Target.Value = Target / 1024
Application.EnableEvents = True

End Sub
 
Back
Top