Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applying formula to active cell

Status
Not open for further replies.

harky

Technical User
Oct 29, 2001
39
0
0
GB
Hi

I have a spreadsheet where I want user values to be multiplied by 9 automatically when they are typed in. Eg, when a user types 5 into cel E6 i want it to automatically change to 45. How can you have a formula run in the background for a cell and still be able to type in values without overwriting the formula?

Any advice appreciated
 
You can't have it in the same cell.

The effect you want can be achieved however using VBA
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.EnableEvents = False
Target = Target * 5
Application.EnableEvents = True
End Sub

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Cheers Loomah

That worked a treat
 
With a couple of extra checks ...


Code:
Option Explicit

Const Mult_Range As String = "A1:B10"

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Me.Range(Mult_Range)) Is Nothing Then Exit Sub
    If Target.HasFormula Then Exit Sub
    If Not IsNumeric(Target.Value) Then Exit Sub
    Application.EnableEvents = False
    Target.Value = Target.Value * 9
    Application.EnableEvents = True
End Sub

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top