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!
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

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:

Watch MrExcel Video

Forum statistics

Threads
1,109,489
Messages
5,529,168
Members
409,853
Latest member
Amy Gassett
Top