macro to expdite editing cell

  • Thread starter Thread starter todd
  • Start date Start date
T

todd

I posted this once but not shwoing up after atleast an hour

I have a number in a cell I need to edit the cell by going
in and adding an = sign in front of the original number,
placing a plus just after the original number , then
entering a new number

so original cell might look like 5.734

then need to add 4.375

I need to keep both numbers so need to do calc but want to
cut down on key strokes

when done needs to read =5.734+4.375 ( a simple calc
giving me the sum of the 2 numbers in the cell

The goal is tohave a short cut key to add an = sign to the
left of a single number then jump to the right of it, add
a plus sign, and give me a blinking cursor to type in my
number I want to add to the back of it.

Thanks much

Todd
 
Watch for linewrap.

Sub CreateFormula()
Dim dblNum As Double, dblAdd As Double

dblNum = ActiveCell.Value
dblAdd = Application.InputBox("Please enter the number to add.",
Type:=2)
ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & ""

End Sub


Tested using Excel 97SR2 on Windows 98SE,

HTH
Paul
 
This is a totally different question - I used your macro
for my other question - it is great!
 
thanks I will try
-----Original Message-----
Watch for linewrap.

Sub CreateFormula()
Dim dblNum As Double, dblAdd As Double

dblNum = ActiveCell.Value
dblAdd = Application.InputBox("Please enter the number to add.",
Type:=2)
ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & ""

End Sub


Tested using Excel 97SR2 on Windows 98SE,

HTH
Paul
---------------------------------------------------------- ----------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
---------------------------------------------------------- ----------------------------------------------------

.
 
I ran it but ran into a snag

works fine if just have a single number in cell

but if have this "=47.25+4.375" & say add 4.5 to it

it puts this in cell

= 51.625+4.5 It is adding the two original numbers
together then adding my new number to the back of it

I probably did not clarify

if I have 47.25+4.375 already in cell and want to add 4.5
to it then when done that action I need the cell to have
the following in it:

"=47.25+4.375+4.5

In the cell to start with I may have one number or there
may be up to 3 or 4 numbers added together with + signs
between them.

Thanks
 
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim sForm as String, sVal as String
On Error GoTo ErrHandler
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then
sVal = Target.Value
If sVal = "" Then Exit Sub
Application.EnableEvents = False
Application.Undo
sForm = Target.Formula
If Left(sForm, 1) <> "=" Then _
sForm = "=" & sForm
sForm = sForm & "+" & sVal
Target.Formula = sForm
End If
ErrHandler:
Application.EnableEvents = True
End Sub

Right click on the sheet tab and paste in the code.

Now start typing numbers into column A.

Just overtype any existing number and it will build your formula.
 
This line checks for column A:
If Target.Column = 1 Then

If Target.Column = 2 Then
would check for B.

Do you mean that you want it to work on either A, B or C?
If target.column < 4 then
 
The issue is my working column or target column will not
always be in A sometimes B or C

thanks will use this
 
Back
Top