Hi,
Can anyone help me? SEE ATTACHED SPREADSHEET FOR EXAMPLE OF PROBLEM.
I want to paste cells from one sheet into another but when I do I want to paste the cells into the "College" column (Far left column in the green TAB : Required Format) so that the data acts as if I have iinserted an equivalent number of rows. The data is sourced from from the blue TAB : Transposed Data. Currently I have to insert the equivalent blank rows first and then paste the data in from the other sheet (very laborious). ANy help would be greatly appreciated.
John Ivanac
Sydney Australia
Last edited by John Ivanac; 11-08-2009 at 05:39 PM.
Try this macro on your sheet as it exists now...
You can change the sheet names in red if needed.Option Explicit Sub CollegeReport() 'JBeaucaire (11/4/2009) Dim LC As Long, LR As Long, NR As Long, i As Long Dim ws As Worksheet 'Setup Application.ScreenUpdating = False Sheets("Transposed Data").Activate LC = Cells(2, Columns.Count).End(xlToLeft).Column Set ws = Sheets("Required Format") ws.Range("A2:F" & Rows.Count).Clear NR = 2 Range("A2").AutoFilter 'Create report For i = 3 To LC Step 5 Range("A2").AutoFilter Field:=i, Criteria1:="<>" LR = Cells(Rows.Count, i).End(xlUp).Row If LR > 2 Then ws.Range("B" & NR) = Cells(1, i - 1) ws.Range("B" & NR).Font.Bold = True ws.Range("B" & NR).WrapText = True Range("A3:A" & LR).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & NR + 1) Range(Cells(3, i), Cells(LR, i + 2)).SpecialCells(xlCellTypeVisible).Copy ws.Range("C" & NR + 1) NR = ws.Range("A" & Rows.Count).End(xlUp).Row + 2 End If Range("A2").AutoFilter Next i 'Cleanup ActiveSheet.AutoFilterMode = False ws.Activate Range("A2").Select ActiveWindow.FreezePanes = True Columns("C:E").HorizontalAlignment = xlRight Cells.Rows.AutoFit Application.ScreenUpdating = True End Sub
=========
How to use the macro:
1. Open up your workbook
2. Get into VB Editor (Press Alt+F11)
3. Insert a new module (Insert > Module)
4. Copy and Paste in your code (given above)
5. Get out of VBA (Press Alt+Q)
6. Save your sheet
The macro is installed and ready to use. Press Alt-F8 and select CollegeReport from the macro list.
Last edited by JBeaucaire; 11-05-2009 at 01:11 AM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Hi Mr Baudelaire,
Thanks so much for getting back to me so quickly ( lightning fast actually!) - I will try the coding soon.
Thanks again
John
Sydney Australia
Hi Jbaulaire,
Here's another challenge and it relates to the same worksheet and macro- can you recode it for the following "xtra" conditions?
1 Insert extra blank row for each set of copied cells
2 for each set of student enrolments have a total (autosum) appear at the bottom of each set of numbers (column 3)
3 Have a Total appear at the bottom of the table alomng with a text name (Column 1) - as per the attached sheet (macro enabled)
Thanks again
You are a genious!
John
Use this version:
Option Explicit Sub CollegeReport() 'JBeaucaire (11/5/2009) Dim LC As Long, LR As Long, NR As Long, i As Long Dim ws As Worksheet 'Setup Application.ScreenUpdating = False Sheets("Transposed Data").Activate LC = Cells(2, Columns.Count).End(xlToLeft).Column Set ws = Sheets("Final Format") ws.Range("A2:F" & Rows.Count).Clear NR = 2 Range("A2").AutoFilter 'Create report For i = 3 To LC Step 5 Range("A2").AutoFilter Field:=i, Criteria1:="<>" LR = Cells(Rows.Count, i).End(xlUp).Row If LR > 2 Then ws.Range("B" & NR) = Cells(1, i - 1) ws.Range("B" & NR).Font.Bold = True ws.Range("B" & NR).WrapText = True Range("A3:A" & LR).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & NR + 1) Range(Cells(3, i), Cells(LR, i + 2)).SpecialCells(xlCellTypeVisible).Copy ws.Range("C" & NR + 1) NR = ws.Range("A" & Rows.Count).End(xlUp).Row + 2 ws.Range("C" & NR - 1) = "TOTAL: " & WorksheetFunction.Sum(Columns(i).SpecialCells(xlCellTypeVisible)) ws.Range("C" & NR - 1).Font.Bold = True ws.Range("C" & NR - 1).Borders(xlEdgeTop).Weight = xlThin End If Range("A2").AutoFilter Next i 'Cleanup ActiveSheet.AutoFilterMode = False ws.Activate Range("A2").Select ActiveWindow.FreezePanes = True Columns("C:E").HorizontalAlignment = xlRight With Range("C" & NR) .Value = WorksheetFunction.Sum(Range("C:C")) .Borders.Weight = xlThick .Interior.ColorIndex = 45 .Font.Size = 20 .Font.Bold = True End With Range("A" & NR) = "Total Enrollments" Range("A" & NR).Interior.ColorIndex = 34 Cells.Rows.AutoFit Application.ScreenUpdating = True End Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Great job again !
Thanks for this - it will save hours and hours of laborious work in the future.
Regards from down under
John
If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].
(Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
OK _ will make sure I do.
Thanks again
John
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks