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.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,744
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?
 

jrosen12

New Member
Joined
Aug 10, 2018
Messages
7
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".
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,744
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?
 

jrosen12

New Member
Joined
Aug 10, 2018
Messages
7
Thank you for your help. I think manually would be best, by clicking a button that has the macro assigned to it.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,744
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
 

Forum statistics

Threads
1,089,450
Messages
5,408,306
Members
403,196
Latest member
annph

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top