Hi,
This is my first time on here so I hope someone is able to help me.
I have a workbook with multiple worksheets. I need to copy data from the first 11 columns of 16 of the worksheets & paste the values in a 'loading' worksheet. The worksheets that I need the data from have a similarity in that they are named '**** Pre Load'. Column 6 of the 11 columns is empty but I need the blank column in the loading file. When pasted into the loading file I need it so that the first sheets data will be pasted in cell A2:K10, for example, the next sheet will be from A11:K25 etc.
If anyone can help I would be extremely greatful.
Thanks,
Rod
Last edited by Rodders; 02-10-2012 at 11:20 AM.
Would you need the filename to be inserted from where the data has been copied?
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
hi,
No that won't be necessary as this is all within one workbook.
Thanks
Use this code in a blank module of your file. Press Alt + F11. It will open a blank code window. On the left hand side, you will find Microsoft Excel Objects, right click and select Insert-> Module. Copy this code into the module window on the right.Come back to your sheet. Go to Tools -> Macro-> Macros and run this macro.Option Explicit Dim i As Long Dim lrow As Long Sub copy_data() 'Copies header For i = 1 To Worksheets.Count If Worksheets(i).Name Like "*Pre Load" And Worksheets(i).Name <> "Loading" Then Worksheets(i).Rows("1:1").Copy Worksheets("Loading").Range("A1") Exit For End If Next i 'Copies data For i = 1 To Worksheets.Count With Worksheets(i) If .Name Like "*Pre Load" And .Name <> "Loading" Then lrow = .Range("A" & .Rows.Count).End(xlUp).Row .Range("A2:K" & lrow).Copy Worksheets("Loading").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) End If End With Next i End Sub
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Thanks for the response.
I've tried it out but it stops on the line:
Worksheets(i).Rows("1:1").Copy Worksheets("Loading").Range("A1")
Woould it be easier if I attached a sample of the workbook?
Rod
Yes please attach. Since it was more of a generic question, i just framed a solution. You will need to change it to match your sheet names.
I guess, your "loading" sheet starts with "l" (small l") while the code asks for a capital L. You can try changing that and checking again.
If you still face a problem, please attach a file.
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
S Figures slim version.xlsx
Hi Arlette,
Please find attached a siplified version of what I am working with.
This might make a bit more sense than in my explanation.
I look forward to hearing from you.
Thanks,
Rod
Your tabs - 1 preload, 2 preload, etc do not have headers. Please insert them so i know which columns need to be copied.
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Hi,
I not sure if I fully understand what you mean by "Headers".
The reason that the Pre Load tabs are just data is that I am using the formula below to extract some of the data from th "Area 1" tab. This formulahas to be in row one otherwise it misses the first cell.
=INDEX(Area 1!$CG$4:$CR$445,1+INT(ROW()/12.0001),ROW()-INT(ROW()/12.0001)*12)
Does this help?
If not could you send me an example of a header, please.
Thank you.
Rod
Should the data be copied one below the other?
By headers i mean the first line which contains the name for the column. If you do not have headers, can you tell me which columns need to be copied?
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Yes. The process should be along the lines of this:
Copy data from "Area1 Pre Load" (Columns A:F & H:K)
Paste this into the same columns in the "Loading File" tab.
Then copy the data from "Area 2 Pre Load" (Columns A:F & H:K) as above.
Paste this under that data from Area 1 in the "Loading File" tab. Then repeat for the other "Area* Pre Load" tabs.
Is this possible?
Rod
Use this code.Option Explicit Dim i As Long Dim lrow As Long Dim lastrow As Long Sub copy_data() Application.ScreenUpdating = False For i = 1 To Worksheets.Count With Worksheets(i) If .Name Like "*Pre Load" And .Name <> "Loading File" Then lrow = .Range("A" & .Rows.Count).End(xlUp).Row lastrow = Worksheets("Loading File").Range("A" & Rows.Count).End(xlUp).Row .Range("A1:F" & lrow).Copy Worksheets("Loading File").Range("A" & lastrow + 1) .Range("H1:K" & lrow).Copy Worksheets("Loading File").Range("H" & lastrow + 1) End If End With Next i Application.ScreenUpdating = True End Sub
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Thanks for this Arlette.
Can this be easily adapted to paste special values?
Cheers,
Rod
For paste special, change the code fromTo.Range("A1:F" & lrow).Copy Worksheets("Loading File").Range("A" & lastrow + 1) .Range("H1:K" & lrow).Copy Worksheets("Loading File").Range("H" & lastrow + 1).Range("A1:F" & lrow).Copy Worksheets("Loading File").Range("A" & lastrow + 1).pastespecial, paste:=xlvalues .Range("H1:K" & lrow).Copy Worksheets("Loading File").Range("H" & lastrow + 1).pastespecial, paste:=xlvalues
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Brilliant!
This works a treat.
Thank you very much.
Rod
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks