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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
Dim FruitSelection as String

FruitSelection = ActiveCell.Value

ActiveWorkbook.Sheets("Sheet2").Range("B3").Value = Fruitselection
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,826
Members
449,051
Latest member
excelquestion515

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