Using .AutoFill with a CELLS() reference
You also have trouble waiting to happen he
With Worksheets("MyQuery")
.Range(Cells(5, 1), Cells(65000, 255)).Clear
.Range(Cells(4, 6), Cells(4, 255)).Clear
Those cells() are unqualified. If myQuery isn't the activesheet, it'll fail.
With Worksheets("MyQuery")
.Range(.Cells(5, 1), .Cells(65000, 255)).Clear
.Range(.Cells(4, 6), .Cells(4, 255)).Clear
Same he
.Range("F4").AutoFill Destination:=.Range(.Cells(4, 5), .Cells(4, 12)), _
Type:=xlFillDefault
or
.Range("F4").AutoFill Destination:=.Range("F4", .Cells(4, 12)), _
Type:=xlFillDefault
Greg Glynn wrote:
Hi Bob,
I changed my code from "Thisworksheet.sheets.range( ...." to the "with/
end with" structure as you suggested. I'm getting "autofill method of
range class failed" on the last line (before the 'end with'). Maybe I
need to Activate the sheet?
With Worksheets("MyQuery")
.Range(Cells(5, 1), Cells(65000, 255)).Clear
.Range(Cells(4, 6), Cells(4, 255)).Clear
.Range("A6").Value = "Agency"
.Range("B6").Value = "Server"
.Range("C6").Value = "Policy"
.Range("D6").Value = "Description"
.Rows("6:6").Font.Bold = True
ReportDays = ReportCriteria.PickFinishDate -
ReportCriteria.PickStartDate
'Write the Dates for the Grid Column Headings
ReDim DateArray(ReportDays + 1)
For i = 0 To ReportDays
.Cells(6, 6 + i) = ReportCriteria.PickStartDate + i
.Cells(6, 6 + i).NumberFormat = "dd mmm"
.Cells(6, 6 + i).HorizontalAlignment = xlCenter
.Cells(5, 6 + i) = ReportCriteria.PickStartDate + i
.Cells(5, 6 + i).NumberFormat = "ddd"
.Cells(5, 6 + i).HorizontalAlignment = xlCenter
DateArray(i + 1) = FormatDateTime(ReportCriteria.PickStartDate + i,
vbShortDate)
Next i
.Range("F4").AutoFill Destination:=.Range(Cells(4, 5), Cells(4,
12)), Type:=xlFillDefault
End With
--
Dave Peterson
|