Copying 2 different cell values into formula using VBA

Julliana

New Member
Joined
Jul 25, 2018
Messages
5
Hello team,

I'm a newbie at macros, and cannot seem to get what I need...

I have sheet 1 with a huge list of client data: accounts (Column D), product names (Column C), amounts (Column E).

What I am aiming is to create a macro that would copy data from cells located in Columns C, D and E (Sheet 1) to specific cell locations in the Sheet2.

Here's the exact scheme below. The values of cells / cells have to be copied accordingly to the formulas on the picture on the right.

I've been trying to work on this for a a while and cannot seem to be a able to create this, especially line 8 on the left screenshot.

https://ibb.co/ee0Vdo

Could you please kindly assist me in guiding through this? :)

Thank you!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Julliana,

Welcome to the Board.

You might consider the following...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Dim rng As Range
Set rng = Range("D2", Cells(Rows.Count, "D").End(xlUp)) 'Assume headers in Row 1
If Not Intersect(Target, rng) Is Nothing Then
    With Sheets("Sheet2")
        .Cells(4, 1).Value = Target.Value
        .Cells(8, 1).Value = Target.Offset(0, -1)
        .Cells(8, 2).Value = Target.Offset(0, 1)
        .Cells(12, 1).Value = "  T " & Target.Value & "FBUL"
        .Cells(13, 1).Value = "  T " & Target.Value & "FBUL"
    End With
    Sheets("Sheet2").Activate
End If
End Sub

The code should be pasted into the Sheet1 module.

Selecting an account in Column D on Sheet 1 will populate the relevant data into Sheet 2 at the specified locations.

Cheers,

tonyyy
 
Upvote 0
Hi Tony,

Thank you very much! A few noob questions remain though...

Should I create a new macro, and edit it by copying the code that You wrote, or should I do it the other way? No additional changes needed to the code?

Thank you in advance!
 
Upvote 0
Should I create a new macro, and edit it by copying the code that You wrote, or should I do it the other way? No additional changes needed to the code?

No, you do not need to create a new macro, nor do you need to edit the code. You might want to view the very short tutorial on how to Copy VBA Code to a Worksheet Module. As stated in Post #2 , the code should be pasted into the Sheet 1 module.

You do not need to "run" the code. The code will be triggered and run automatically when you select a cell in Column D of Sheet 1.
 
Upvote 0
I follow each and every step of the video, however at 2:28 where the macro should be selected, I don't see any macro to choose from...
 
Upvote 0
I have data in Sheet 1, accounts starting from cell D2, and in Sheet 2 data ranging from A1-A13.
I see no macro selection despite copying everything like the video describes...
 
Upvote 0
I see no macro selection...

Again...
You do not need to "run" the code. The code will be triggered and run automatically when you select a cell in Column D of Sheet 1.

What happens when you select different cells/accounts in Column D of Sheet1?
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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