Solved

Excel VB Sripting

Posted on 2013-01-15
3
236 Views
Last Modified: 2013-01-16
Hello people, I have an excel Spreadsheet that has a sheet in an excel workbook named Summary and multiple other sheets (the sheet names can be named different).  what i am looking to accomplish is combing the cells in C9:H44 into the summary sheet.  All the sheets have the same information in them but for instantance sheet 1 would have A's in the above cells Sheet two would have B's and so on.  On the summary sheet it would basically combine the cells using the & function and would be displayed as AB.  I have some sample code that completes this but it only works if the sheets are named what they are in the code. Can i set this up as a varible and have it go through all the sheets.  

thanks in advance.

Sheets("Summary").Select
    Range("C9").Select
    ActiveCell.FormulaR1C1 = ""
    Range("C9").Select
    ActiveCell.FormulaR1C1 = _
        "='sheet2'!RC&'Person2'!RC&sheet3!RC&sheet!RC"
    Range("C9").Select
    Selection.AutoFill Destination:=Range("C9:C45"), Type:=xlFillDefault
    Range("C9:C45").Select
    Selection.AutoFill Destination:=Range("C9:H45"), Type:=xlFillDefault
    Range("C9:H45").Select
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    ActiveWindow.SmallScroll Down:=-9
0
Comment
Question by:kkenison
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
Comment Utility
Hi, kkenison.

Please see attached. The code is...
Option Explicit

Const xRANGE = "C9:H44"

Sub Summarise_Sheets()
Dim i          As Long
Dim j          As Long
Dim xArray_Wrk As Variant
Dim xArray_Out As Variant
Dim xSheet     As Worksheet

Sheets("Summary").Range(xRANGE).ClearContents
xArray_Out = Sheets("Summary").Range(xRANGE)

For Each xSheet In ThisWorkbook.Sheets
    If xSheet.Name <> "Summary" Then
        xArray_Wrk = xSheet.Range(xRANGE)
        For i = 1 To UBound(xArray_Wrk, 1)
            For j = 1 To UBound(xArray_Wrk, 2)
                If xArray_Wrk(i, j) <> "" Then xArray_Out(i, j) = xArray_Out(i, j) & xArray_Wrk(i, j)
            Next
        Next
    End If
Next

Sheets("Summary").Range(xRANGE) = xArray_Out

End Sub

Open in new window

Edit:Range converted to a constant to make it easier to change.

Regards,
Brian.Summarising.xlsm
0
 

Author Closing Comment

by:kkenison
Comment Utility
Thank you very much for your help this worked perfectly.
0
 
LVL 26

Expert Comment

by:redmondb
Comment Utility
Thanks, kkenison!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now