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.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,512
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,512
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,512
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,081,855
Messages
5,361,714
Members
400,649
Latest member
tcisrly

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top