Solved

format calculator in same cell

Posted on 2014-04-29
7
151 Views
Last Modified: 2014-05-15
Is there anyway in excel, if a user enters a value in a cell, i.e. 4, it automatically performs a calculation to change that value. For example in A1, if a user types 4, in cell B1 I have the value 4 pre-populated, so I want A1 to show the output of the formula

A1*B1,

so if the user types 4, it will return 16. I cant see anyway to do this via formatting.
0
Comment
Question by:pma111
  • 3
  • 3
7 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40029170
Hi,

Why don't you want the result in another cell?

Regards
0
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40029178
Hello,

I don't think so that the same can be done.

So Rethink on it....
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40029195
Put this code in the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
    Target.Value = Target.Value * Target.Offset(, 1).Value
End Sub

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40029207
Hi,

Of course it is possible to make it but it is bad design to have input and result at the same place
Say your are tipping 12 answer a call and do not remember what you tipped you won't know whether 12 is the input or the result.

Regards
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 250 total points
ID: 40029216
Sorry, this is the code you need:
Dim blnFlag As Boolean

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        If Not blnFlag Then
            blnFlag = True
            Target.Value = CLng(Target.Value) * CLng(Target.Offset(, 1).Value)
        End If
    End If
    blnFlag = False
End Sub

Open in new window

0
 
LVL 49

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
ID: 40029245
@MacroShadow

Wouldn't be easier to disable the events instaed of a flag

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        Target.Value = Target.Value * Target.Offset(, 1).Value
    End If
Application.EnableEvents = True
End Sub

Open in new window

0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40029256
Yes it would. Although personally I wouldn't recommend it without thoroughly examining the workflow.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question