Add an amount to a cell using a function procedure called from a Sub procedure

D_Licious

New Member
Joined
May 6, 2015
Messages
11
Hi everyone,

I'm trying to add an amount to a cell using a function procedure called from a Sub procedure. I know you could do this with just a Sub directly, but I want to learn how to do it via calling a Function from a Sub.

So I have these 2 procedures (1 Sub & 1 Function):

Function Addtothatcell(cell)
Addtothatcell = cell + 1
End Function

Sub CallThatStuff()

Addtothatcell (e3)

End Sub


As you can see, I'm trying to use the Sub to "call" the Function. And what it ultimately needs to do is add 1 to whatever is in cell E3. When I run the "Sub CallThatStuff", it's not giving me an error, but it's also not adding the 1 to the cell. Does anyone know what is wrong?

thanks,
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
A simple solution would be
VBA Code:
Function Addtothatcell(cell)
    Addtothatcell = cell + 1
End Function

Sub CallThatStuff()
    [e3] = Addtothatcell([e3])
End Sub

but if you don't understand what's going on I would recommend to take a look over here:
 
Upvote 0
Solution
A simple solution would be
VBA Code:
Function Addtothatcell(cell)
    Addtothatcell = cell + 1
End Function

Sub CallThatStuff()
    [e3] = Addtothatcell([e3])
End Sub

but if you don't understand what's going on I would recommend to take a look over here:
 
Upvote 0
You are welcome. Good luck and happy coding :)
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,139
Members
449,361
Latest member
VBquery757

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top