Hi,
I've decided to try going another route from an earlier problem I had which I wasn't able to fix. What I'm trying to do now is clear the contents of all rows below the first blank cell in column A for all open workbooks and then do a little formatting. Here is the full code:
Sub test()
Dim wbl As Workbook
For Each wbl In Application.Workbooks
wbl.Activate
Dim LastRow As Long, myCell As Range, myRange As Range
Dim myCell1 As Range
LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
Set myCell1 = Range("A" & LastRow)
ActiveSheet.Range("A1").End(xlDown).Offset(1, 0).Select
Set myCell = ActiveCell
Set myRange = Range(myCell, myCell1)
myRange.EntireRow.ClearContents
Rows("1:1").Select
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Application.CutCopyMode = False
Next wbl
End Sub
I get the aforementioned error on the line
ActiveSheet.Range("A1").End(xlDown).Offset(1, 0).Select
If I remove
and have two workbooks open at the same time, it just runs the macro on the first workbook twice and doesn't touch the second workbook.
If I remove
Dim LastRow As Long, myCell As Range, myRange As Range
Dim myCell1 As Range
LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
Set myCell1 = Range("A" & LastRow)
ActiveSheet.Range("A1").End(xlDown).Offset(1, 0).Select
Set myCell = ActiveCell
Set myRange = Range(myCell, myCell1)
myRange.EntireRow.ClearContents
from the code and leave everything else the same then it properly bolds and underlines the correct cells in each sheet and works perfectly. So I know the problem must be somewhere in the above set of code (or maybe how it interacts with the Workbooks Collection object.) Also, I am running this code from PERSONAL.xlsb so I'm not sure if that makes a difference when referencing workbooks.
Any ideas?
Bookmarks