Copy/paste VBA code

jrosen12

New Member
Joined
Aug 10, 2018
Messages
7
Hello,

I am a beginner (new learner) of VBA. I am trying to create a macro that does the following:
The user will be on sheet "Values" He/she will type in three values in columns A, B, and C. I would like the macro to copy these values, and paste them into Sheet "GL" in cells E6,F6, G6. Once they have done that, I want it to copy G9 on Sheet "GL" and paste it in column E on "Values" next to its corresponding row.

So, for example:

"Values" A1:C1 has values 1, 2, 3
The Macro Copies 1, 2, 3 and pastes in Sheet "GL" in E6:G6
Then it copies G9 on the same tab
The Macro goes back to "Values" and pastes this value into E1.
Then it loops until it reaches a blank A cell in "Values".
Please let me know if I need to clarify what I need.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Using the method you described, the end result will display the data from the last row of "Values" in E6:G6 of "GL" and all the cells in column E of "Values" will have the value of G9 from "GL". Is this what you want?
 
Upvote 0
There may be a better way of getting at what I want, but my end goal is that the values in column E on "Values" will have a corresponding value for its row.

G9 on "GL" is a vlookup formula based on values in E6:G6.

So rows 2-on may have a different value depending on what's in A:C in "Values".
 
Upvote 0
Do you want to do this automatically as you enter the data in columns A:C in each row? In other words, you enter data in A1, then in B1 and finally in C1. After you enter the data in C1 and exit the cell, all the copying and pasting will be done automatically for row 1. Then you would enter the data in A2:C2, and so on. The other alternative would be to run a macro manually on all the rows at once after you have entered all the data in all the rows. Which method would work best for you?
 
Upvote 0
Thank you for your help. I think manually would be best, by clicking a button that has the macro assigned to it.
 
Upvote 0
Try:
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim rng As Range
    Dim LastRow As Long
    LastRow = Sheets("Values").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Sheets("Values").Range("A1:A" & LastRow)
        rng.Resize(, 3).Copy Sheets("GL").Range("E6")
        Sheets("Values").Cells(rng.Row, "E").Value = Sheets("GL").Range("G9").Value
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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