You could use your existing code and just select a sheet, run your code, select
a different sheet, run your code...
Sub doall()
dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.select
call yourproc
next wks
end sub
or if you include it in the newer version:
Option Explicit
Sub testme01()
Dim wks As Worksheet
Dim SumWks As Worksheet
Dim myCell As Range
Dim oRow As Long
Set SumWks = Worksheets.Add
oRow = 0
For Each wks In ActiveWorkbook.Worksheets
If wks.Name = SumWks.Name Then
'do nothing
Else
wks.Select
Call YourProc
For Each myCell In Intersect(wks.UsedRange, wks.Columns(2)).Cells
If myCell.Interior.ColorIndex = 3 Then
oRow = oRow + 1
myCell.EntireRow.Copy _
Destination:=SumWks.Cells(oRow, "A")
End If
Next myCell
End If
Next wks
End Sub
sub YourProc()
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
Selection.Copy
Range("A1").Select
ActiveSheet.Paste
Columns("A:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = "=R[-1]C"
End Sub
I think I'd add a formula after all the copying is done:
=counta(B1:IV1) after inserting a new column A.
Then I could tell how many entries are in each row. (This'll work ok if no
cells are empty).
david said:
Dave,
Thanks for the VB code for extracting data from worksheets by color.
Rather than checking the entire worksheet cell by cell for colored
cells, I`m thinking it might be easier if the programme just checks the
second column of every row in the worksheet.
If it is red, then extract the entire row of cells of data and list all
the rows in the new worksheet. This would be done for all of the
worksheets in the workbook. So the new worksheet would contain all the
red rows from all the worksheets in the workbook.
All of rows in the worksheets have a standard number of columns (from
columns A to AB on the excel sheet). (If possible, it would be good if
the computer flagged when a worksheet did not have the standard A to AB
number of columns.)
How can I find out the right number for red in my color index?
I`ve also created the following code for preparing each of the
worksheets for the extraction process:
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
Selection.Copy
Range("A1").Select
ActiveSheet.Paste
Columns("A:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = "=R[-1]C"
End Sub
Would it be possible to alter the code so that it runs this procedure on
every worksheet in the workbook? And then add the extraction procedure
(which creates the new data sheet and extract the rows of data by color)
after this.
Overall, this is what the VB does:
1) It prepares the worksheets for the extraction process (this is done
for each worksheet in the workbook): the procedure for each worksheet
is above.
2) When all worksheets prepared, a new empty data sheet is created.
3) Search through each row of the worksheet for every row where the
second column is red. If column 2 of the row is red, extract the whole
row of cells and list in the new data sheet. Do procedure for all
worksheets.
4) New data sheet contains all rows in worksheets in workbook for which
the second column is red.
Hope the description isn`t too complicated. Thanks very much.
Dave