Pasting to a location specified within an active cell using VBA?

dougmarkham

Active Member
Joined
Jul 19, 2016
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I am attempting to finish off a project for the team and wondering if VBA can achieve an unusual task.

Goal: to copy the contents of cell (M3) in worksheet 2 into clipboard; thereafter, to paste the clipboard contents into a location in worksheet 1 i.e., into a cell which is specified by an active cell in worksheet 2 (selected prior to running the macro). In other words, I want the macro to refer to a location stored within an active cell but to paste clipboard into that location in worksheet 1.

Situation
I have two worksheets:
Worksheet 1 - Task manager (containing Table 1)
Worksheet 2 - Amending Tasks (containing Table 2)


Worksheet 1, Table 1:


  • The Task manager (Table 1) contains the full list of tasks with four named ranges corresponding to JobNumber, JobName, Detail and DetailsLocation.

JOB NUMBER (A2)TASKS STATUS (B2)TASK TYPE (C3)DATE (D3)TIME (E3)JOB NAME (F3)JOB DETAILS (G3)DETAILS LOCATION (H3)PRIORITY (I3)REQUESTED DATE (J3)
11EXCEL VBA07/12/201709:00JOB ASLKJDLFKJDLJKFLDJFKJDLFJKDFJKLDJFKLJDKLFJKLDJG4URGENT07/12/2017
21ADMIN07/12/201709:00JOB BADJGDAJKGLSAJDLFGJDAFLGJFDLJGALJFLDJSKLDAJFGKG5CURRENT INITIATIVE15/01/2018
31OTHER07/12/201709:00JOB CAJGKLFJGJKHDAJDFKLASDJFGKJDALFJKLSDAJFKLDJKFG6BY TOMORROW08/12/2017

<tbody>
</tbody>













  • whereas, the Amending Tasks worksheet (Table 2) contains only active tasks.

Worksheet 2 - Table 2

PRIORITY (B4)JOB NUMBER (C4)JOB NAME(D4)Details Location (E4)
11JOB AG4
22JOB BG5
3 etc...3 JOB CG6

<tbody>
</tbody>








In Worksheet 1, a user inputs tasks as they are assigned. Over time, this generates a big list that grows and becomes a hassle to search through---i.e., because the cells in the job details column become huge.

So, I created a second worksheet (2) containing a table which uses INDEX MATCH to extract only active tasks (active task = 1, completed task = 0 in column B of Table 1 below). Also in worksheet 2---next to the Table 2---I have a big cell (M3) which the user can write amendments to the Job Details for a particular task. I would like the user to be able to click a button to paste the amended job details from cell M3 back into the relevant cell in table 1.

E.g., the process for the user would go something like:
1) Work on a specific task e.g., Job A (in Table 2)
2) Enter an amendment that task's Job details in cell M3
3) Click on cell E5 in Table 2 to make it the active cell
4) Click the button to activate the macro which pastes M3 to cell G4 of Table 1.

My idea is for the user to select a cell in column E of Table 2 corresponding to their specific task (i.e., so the active cell then contains a cell address which the macro will use to paste to that cells address in Table 1) and then run the macro to paste M3 contents into Worksheet 1.

So far I've written the following VBA:
ThisWorkbook.Sheets("Amending Tasks").Activate
ActiveSheet.Range("M3").Select
Selection.Copy

My question is: if it is possible, how would one instruct excel via VBA code to paste the contents of M3 to a cell address in Table 1 (worksheet 1) that is defined by an active cell in Table 2 (worksheet 2) e.g., cell E5 in Table 2 contains the cell address G4??

Kind regards,

Doug
 
Last edited:
Not sure if I've understood correctly, but try this
Code:
    Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range(ActiveCell.Value).Value = Sheets("[COLOR=#ff0000]Test[/COLOR]").Range("M3")
Changing sheets names in red to suit
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Not sure if I've understood correctly, but try this
Code:
    Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range(ActiveCell.Value).Value = Sheets("[COLOR=#ff0000]Test[/COLOR]").Range("M3")
Changing sheets names in red to suit

I tried this macro out:

Sub CopyM3toTableOneActiveCell()
Sheets("Amending Tasks").Range(ActiveCell.Value).Value = Sheets("Task manager").Range("M3")
End Sub

It seemed to run without error code but didn't do anything (that I can see).

Kind regards,

Doug.
 
Upvote 0
Did the activecell have a value like G4?
 
Upvote 0
Did the activecell have a value like G4?

Yes.

For visual reference, the cells I want to select as active are in purple i.e., E5:E7: so G4 or G5 or G6 etc.

Worksheet 2 - Table 2

PRIORITY (B4)JOB NUMBER (C4)JOB NAME(D4)Details Location (E4)
11JOB AG4
22JOB BG5
3 etc...3JOB CG6

<tbody>
</tbody>


So E5, E6 and E7 in table 2 need to provide the macro with the cell address for Table 1 column G4, G5, G6 (JOB DETAILS) in blue.


JOB NUMBER (A2)TASKS STATUS (B2)TASK TYPE (C3)DATE (D3)TIME (E3)JOB NAME (F3)JOB DETAILS (G3)DETAILS LOCATION (H3)PRIORITY (I3)REQUESTED DATE (J3)
11EXCEL VBA07/12/201709:00JOB ASLKJDLFKJDLJKFLDJFKJDLFJKDFJKLDJFKLJDKLFJKLDJG4URGENT07/12/2017
21ADMIN07/12/201709:00JOB BADJGDAJKGLSAJDLFGJDAFLGJFDLJGALJFLDJSKLDAJFGKG5CURRENT INITIATIVE15/01/2018
31OTHER07/12/201709:00JOB CAJGKLFJGJKHDAJDFKLASDJFGKJDALFJKLSDAJFKLDJKFG6BY TOMORROW08/12/2017

<tbody>
</tbody>
 
Upvote 0
What is the sheet name containing table 2?
 
Upvote 0
Normally when writing scripts we do not like to refer to cells as the "activecell"

And we normally do not like using "Select"

If you wanted to put "George" into Range("J45") of sheet named "Bob" we would write the script like this:

Sheets("Bob").Range("J45").value="George"

Or something like this if you also wanted the formatting also:

Sheets("Sally").Range("B1").Copy Sheets("People").Range("J3")

And when posting images it's also best to show what columns we are dealing with
We cannot always assume the column on the far left of the image is column "A"
And do not say Column("Sally") that then requires us to figure out what column that is.
 
Upvote 0
In that case try
Code:
Sub CopyM3toTableOneActiveCell()
Sheets("Task manager").Range(ActiveCell.Value).Value = Sheets("Amending tasks").Range("M3")
End Sub
 
Upvote 0
In that case try
Code:
Sub CopyM3toTableOneActiveCell()
Sheets("Task manager").Range(ActiveCell.Value).Value = Sheets("Amending tasks").Range("M3")
End Sub

Hi Fluff,

You've cracked it, awesome :) Thanks for your help!
This will be very useful in future. How did you learn VBA?

Kind regards,

Doug.
 
Upvote 0
Glad to help & thanks for the feedback.

I've learnt most of what I know from this site. Either hunting for answers that I could understand (to some extent) & modify for my needs, or by studying solutions that others have offered, on threads that I've been involved with.
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

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