simple code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to kow a simple code for taking a number from a cell in an excel worksheet and then do some addition to it and reurning the new number into the work sheet
Thank You
 
Hi
try something like
sub foo()
dim old_val
old_val = activecell.value
old_val = old_val + 3
activecell.offset(0,1) . value = old_val
end sub

Though why not use a simple worksheet function

--
Regards
Frank Kabel
Frankfurt, Germany

rstewart said:
I would like to kow a simple code for taking a number from a cell in
an excel worksheet and then do some addition to it and reurning the new
number into the work sheet.
 
I'm not exactly sure what you're looking for, but some simple
code like the following may suffice:

Sub AAA()
Dim V As Double
V = Range("A1").Value
V = V + 1
Range("A2").Value = V
End Sub

If you're looking for a function that can be called from a
worksheet cell, try something like the following:

Function Test(V As Double) As Double
Test = V+1
End Function

You'd then call this function from a worksheet cell with a
formula like =TEST(123)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




rstewart said:
I would like to kow a simple code for taking a number from a
cell in an excel worksheet and then do some addition to it and
reurning the new number into the work sheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top