Repeating data using column contents in to rows

LeighMacKay7

New Member
Joined
Oct 11, 2022
Messages
34
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Web
Hi, hoping somebody can offer me some advice/solution.
I have received an excel workbook, which contains 24 columns of data.
However, columns C to M contain different names, under columns called, Project Lead, Co-Investigator 1, Co-Investigator 2, and so forth (all the way up to Co-Investigator 9).
I'd like to repeat the data in columns A, B, N to X. But have a new row for each of the Project Leads & Co-Investigators.
Is this possible?
 
You haven't answered the first question from my previous reply.

Are you working with data tables?
If so, we will probably need to insert a new row into the table before copying the data down.
So this is an EXTERMELY important question we need answered.
Please also let us know the name of the table.

Also, do you have anything at all in column A after cell A11 (your last row of data)?
Apologies.

No, not working with data tables. Based on my understanding.

And yes, the data goes from range A1 to X90 on the real data sheet.

My example dataset range is A1 to X11
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I see you marked my first post as the solution.
Does that mean you got it to work, or are you still having issues?
 
Upvote 0
If you do indeed have a table, this code should do what you want:
VBA Code:
Sub AddRowToTable()

    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim lrow As Long

    Set ws = ActiveSheet
    Set tbl = ws.ListObjects("Table1")

'   Find last row in table with data
    lrow = Range("A1").End(xlDown).Row

'   Add new row to bottom of table
    tbl.ListRows.Add
   
'   Copy values from last row to new row
    Cells(lr + 1, "A").Value = Cells(lr, "A").Value
    Cells(lr + 1, "B").Value = Cells(lr, "B").Value
    Cells(lr + 1, "N").Value = Cells(lr, "N").Value
    Cells(lr + 1, "X").Value = Cells(lr, "X").Value

End Sub
Just substitute "Table1" in the code with the actual name of your table.
I have changed my data to a table on the back of this and called it "RES.tbl" To which I have changed the text.

I am getting debug error.
1694783355279.png
 
Upvote 0
OK. Please do NOT mark a post as the solution, if the problem is not solved!
That is a bit misleading and confusing.

What is the exact error message you are getting?
If you hover over the "lr" variable in your code when you get this error, what does it show as its value?
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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