Ok,now that one piece of confusion is cleared up (where the company names are held), and I think I've got one other piece of confusion cleared up (the number of columns per item in the original dataset is 13, not 12 as I had on the last revision), we can now get down to business.
I'm going to ask you to change something in the following code. You said that all the sheetnames are the same, except that they are followed by 1, 2, ... ,14. There's a line
If wsInput.Name Like "TheCommonName*" Then
where you should replace the "TheCommonName*" with "Data*" or "Companies*" (notice the star) with whatever is your naming convention -- provided that all worksheets are in the same workbook. If they aren't, you'll need to remove that line, this line
For Each wsInput In ActiveWorkbook.Worksheets
and these two lines at the end.
(make sure that the 'end if' directly above the Next wsInput is removed.
and then, right above
Set wsOutput = Worksheets.Add
put back in
Set wsInput = ActiveSheet
any way, hopefully this won't be a problem, so try this:
Sub FixFourColumnData()
Dim lCtrIn As Long
Dim lCtrOut As Long
Dim lColNbr As Long
Dim wsInput As Worksheet
Dim wsOutput As Worksheet
Set wsOutput = Worksheets.Add
lCtrOut = 2
For Each wsInput In ActiveWorkbook.Worksheets
'the next line is where you should put in the text common
'to all the worksheets you're interested in. Be sure to
'use a * for a wildcard where the number would appear.
If wsInput.Name Like "TheCommonName*" Then
lColNbr = 1
lCtrIn = 3
Do
'check to see if we're at the end of a col.
'if so, move over to next group of 13, and reset
'to the first row of data
If wsInput.Cells(lCtrIn, lColNbr) = "" Then
lColNbr = lColNbr + 13
lCtrIn = 3
If wsInput.Cells(lCtrIn, lColNbr) = "" Then Exit Do
'check to see if the first item in the 13 column group
'is blank. if it's blank, we've ran through the
'whole data set for the given company.
End If
'copy the info to the output sheet
wsOutput.Cells(lCtrOut, 1) = wsInput.Cells(1, lColNbr + 1)
wsOutput.Range(wsOutput.Cells(lCtrOut, 2), wsOutput.Cells(lCtrOut, 14)).Value _
= wsInput.Range(wsInput.Cells(lCtrIn, lColNbr), wsInput.Cells(lCtrIn, lColNbr + 12)).Value
'set the counter to look at the next row on the input sheet.
lCtrIn = lCtrIn + 1
'set the counter to output to the next row on the output sheet
lCtrOut = lCtrOut + 1
Loop
End If
Next wsInput
End Sub
Bookmarks