Very Basic VBA: Store value then put into another cell

z3115

Board Regular
Joined
Nov 1, 2013
Messages
71
Hi,

I am very new to VBA and have a simple question:

Say I want to take the value of whatever cell is currently active, and then put is as the value of another cell on a different sheet at a later point in time (I have some other code going in between, so I can't just copy / paste).

Example: User has a cell containing "apples" highlighted (let's say sheet 1 cell A1)
-> Other vba code runs, meaning the "apples" cell is no longer highlighted
Now I need to set Sheet 2 cell B3 equal to "apples".

I tried
Code:
Dim fruitselection as string
fruitselection = activecell.text

sheets(sheet1).range("B3").value = fruitselection

Any suggestions? I know this is probably a simple question, but thank you for the help!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

ChrisBM

Board Regular
Joined
Sep 22, 2014
Messages
215
Code:
Dim FruitSelection as String

FruitSelection = ActiveCell.Value

ActiveWorkbook.Sheets("Sheet2").Range("B3").Value = Fruitselection
 

z3115

Board Regular
Joined
Nov 1, 2013
Messages
71
Thanks ChrisBM! That's why I love this site.

Slight adjustment: The code that runs in between will change what the "active cell" is, so is there a way to store what the value of the active cell at the start of the macro is, and then use it later?

(put another way, by the time I actually use the cell.Value = FruitSelection, the activecell is no longer "apples".
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,627
Messages
5,838,444
Members
430,548
Latest member
hh_dh2001

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
Top