Excel VB Sripting

Posted on 2013-01-15
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.

    ActiveCell.FormulaR1C1 = ""
    ActiveCell.FormulaR1C1 = _
    Selection.AutoFill Destination:=Range("C9:C45"), Type:=xlFillDefault
    Selection.AutoFill Destination:=Range("C9:H45"), Type:=xlFillDefault
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    ActiveWindow.SmallScroll Down:=-9
Question by:kkenison
  • 2
LVL 26

Accepted Solution

redmondb earned 500 total points
ID: 38781041
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

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)
    End If

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

End Sub

Open in new window

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


Author Closing Comment

ID: 38784091
Thank you very much for your help this worked perfectly.
LVL 26

Expert Comment

ID: 38784115
Thanks, kkenison!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

930 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

14 Experts available now in Live!

Get 1:1 Help Now