Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a workbook with 10 worksheets (tabs) each with a Header Row with the
month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub combinesheets()
First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: I have a workbook with 10 worksheets (tabs) each with a Header Row with the month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
Thanks for the response. This is my first attempt at using a macro though! I took your script and copied and pasted it in as a module. I then wnet to "Tools", "Macros", saw the "Combinesheets" macro and hit "Run". It came back though and said "Compile Error: Variable Not Defined" and the "First = True" statement at the top was grayed out. Am I doing something wrong in loading or execution? Thanks, Brian "Joel" wrote in message ... Sub combinesheets() First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: I have a workbook with 10 worksheets (tabs) each with a Header Row with the month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Depending on the way your workbook is set up you are required to define
variables. My workbook doesn't. I added the definitaions below Sub combinesheets() Dim First As Boolean Dim Sht As Sheets Dim SummarySht As Sheets Dim NewRow As Long Dim LastCol As Long Dim LastRow As Long Dim AddedRow As Long First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: Joel, Thanks for the response. This is my first attempt at using a macro though! I took your script and copied and pasted it in as a module. I then wnet to "Tools", "Macros", saw the "Combinesheets" macro and hit "Run". It came back though and said "Compile Error: Variable Not Defined" and the "First = True" statement at the top was grayed out. Am I doing something wrong in loading or execution? Thanks, Brian "Joel" wrote in message ... Sub combinesheets() First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: I have a workbook with 10 worksheets (tabs) each with a Header Row with the month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I've tried this again but am still getting a Compile Error. Any suggestions
on maybe some settings I should change? Thanks, Brian "Joel" wrote in message ... Depending on the way your workbook is set up you are required to define variables. My workbook doesn't. I added the definitaions below Sub combinesheets() Dim First As Boolean Dim Sht As Sheets Dim SummarySht As Sheets Dim NewRow As Long Dim LastCol As Long Dim LastRow As Long Dim AddedRow As Long First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: Joel, Thanks for the response. This is my first attempt at using a macro though! I took your script and copied and pasted it in as a module. I then wnet to "Tools", "Macros", saw the "Combinesheets" macro and hit "Run". It came back though and said "Compile Error: Variable Not Defined" and the "First = True" statement at the top was grayed out. Am I doing something wrong in loading or execution? Thanks, Brian "Joel" wrote in message ... Sub combinesheets() First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: I have a workbook with 10 worksheets (tabs) each with a Header Row with the month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I left a colon out of one statment. If there are additional problems let me
know which line has the error. It willusually be highlighted. Excel 2003 didn't give me a compiler error, but the line needed to be fixed. from Sht.Rows(1).Copy Destination=SummarySht.Rows(1) to Sht.Rows(1).Copy Destination:=SummarySht.Rows(1) "leimst" wrote: I've tried this again but am still getting a Compile Error. Any suggestions on maybe some settings I should change? Thanks, Brian "Joel" wrote in message ... Depending on the way your workbook is set up you are required to define variables. My workbook doesn't. I added the definitaions below Sub combinesheets() Dim First As Boolean Dim Sht As Sheets Dim SummarySht As Sheets Dim NewRow As Long Dim LastCol As Long Dim LastRow As Long Dim AddedRow As Long First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: Joel, Thanks for the response. This is my first attempt at using a macro though! I took your script and copied and pasted it in as a module. I then wnet to "Tools", "Macros", saw the "Combinesheets" macro and hit "Run". It came back though and said "Compile Error: Variable Not Defined" and the "First = True" statement at the top was grayed out. Am I doing something wrong in loading or execution? Thanks, Brian "Joel" wrote in message ... Sub combinesheets() First = True For Each Sht In ThisWorkbook.Sheets If First = True Then 'create new summary worksheet Set SummarySht = Worksheets.Add(after:=Sheets(Sheets.Count)) 'copy header Row to new sheet Sht.Rows(1).Copy Destination = SummarySht.Rows(1) NewRow = 2 First = False End If LastCol = Sht.Cells(1, Columns.Count).End(xlToLeft).Column LastRow = Sht.Range("A" & Rows.Count).End(xlUp).Row For RowCount = 2 To LastRow AddedRow = False For ColCount = 2 To LastCol If Sht.Cells(RowCount, ColCount) = "" Or _ Sht.Cells(RowCount, ColCount). _ Interior.ColorIndex < xlNone Then If AddedRow = False Then 'add header column SummarySht.Range("A" & NewRow).Value = _ Sht.Range("A" & RowCount).Value AddedRow = True End If If Sht.Cells(RowCount, ColCount) = "" Then 'Add X for empty cells SummarySht.Cells(NewRow, ColCount) = "X" Else NewSht.Cells(RowCount, ColCount).Copy _ Destination:=SummarySht.Cells(NewRow, ColCount) End If End If Next ColCount If AddedRow = True Then AddedRow = AddedRow + 1 End If Next RowCount Next Sht End Sub "leimst" wrote: I have a workbook with 10 worksheets (tabs) each with a Header Row with the month of July dates across the top and a Header Column with other information running down the side. What macro would search all 10 sheets for the last date (column) that might have an entry from any of the rows, search back from there through July 1st and identify all blank cells or cells with a red "fill" and consolidate all of them on a new worksheet? Thanks for any help, Brian |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Finding data amongst empty cells | Excel Discussion (Misc queries) | |||
Finding number of empty cells | Excel Programming | |||
Finding Empty Cells | Excel Programming | |||
finding/highlighting empty cells | Excel Programming | |||
Macro trouble finding 'empty' cells | Excel Programming |