Macro to Paste cell based on next cell selected

djclifton

New Member
Joined
Jul 26, 2016
Messages
13
Hi, I am a very basic user of VBA and was wondering if anyone with a little more experience might be able to help me with a solution to a problem that I have.

I have a function that I need to create a macro for that does the following;

1. Click on a cell in worksheet 'A'
2. Automatically display worksheet 'B'
3. Click on a cell in worksheet 'B'
4. Automatically return to worksheet 'A' and populate the cell originally clicked in worksheet 'A' with the contents of the cell clicked on in worksheet 'B'

Does anyone think that this multi step functionality is possible?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi and welcome to the forum.

Try the following macro with activation by Ctrl + Key (see Other ways to run a macro if you're unsure how to do this).

Code:
Sub Copy_data()
Dim rReturn As Range, rSelectRange As Range
Set rReturn = ActiveCell
Sheets("Sheet2").Activate 'change to the name that you require

On Error GoTo end_nice
Set rSelectRange = Application.InputBox("Select the range to copy", Type:=8)

If rSelectRange Is Nothing Then GoTo end_nice
If rSelectRange.Count <> 1 Then GoTo end_nice

rReturn.Value = rSelectRange.Value

end_nice:
    rReturn.Parent.Activate
End Sub
 
Upvote 0
Perhaps this :

Put this in "Sheet1" module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Sheets("Sheet2").Activate
End Sub

Put this in "Sheet2" module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim cel As Range
Set cel = ActiveCell
Sheets("Sheet1").Activate
ActiveCell = cel
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,315
Messages
6,124,213
Members
449,148
Latest member
sweetkt327

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