View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Autofill method of range class failed

For Each ws In Worksheets
If ws.Name < "National (2G-3G)" And ws.Name < "National (2G)" And ws.Name
< "National (3G)" And ws.Name < "National (COW)" And ws.Name < "TI Report
(2G-3G)" Then
with ws
lastcol=.cells(6,columns.count).end(xltoleft).colu mn
.Rows("6:6").Insert Shift:=xlDown
' .Range("A6").Value = "=SUBTOTAL(3,A7:A1999)"
' .Range("A6").value=.Range("A6").value
'or
.Range("A6").value=application.SUBTOTAL(3,.range(" A7:A1999")
.Cells(6, 1).AutoFill .Range(cells(6,1),cells(6,lastcol))
end with
End If
Next


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Appache" wrote in message
...
Hi,

I have an error on the code below. Here is the line that cause the error
message.

Selection.AutoFill Destination:=ws.Range("A6:" & Cells(6,
Columns.Count).End(xlToLeft).Address & ""), Type:=xlFillDefault

If I use this (when I use EY6 instead of using cells(...) )

Selection.AutoFill Destination:=ws.Range("A6:EY6"), Type:=xlFillDefault

it doesn't give an error but I need to use the cell to find the last
column
filled in the row.


For Each ws In Worksheets
If ws.Name < "National (2G-3G)" And ws.Name < "National (2G)" And
ws.Name
< "National (3G)" And ws.Name < "National (COW)" And ws.Name < "TI
Report
(2G-3G)" Then

Worksheets(ws.Index).Activate
ws.Rows("6:6").Select
Selection.Insert Shift:=xlDown

Range("A6").Value = "=SUBTOTAL(3,A7:A1999)"
ws.Range("A6").Select
Selection.Copy
ws.Range("A6").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False

' Selection.AutoFill Destination:=ws.Range("A6:EY6"),
Type:=xlFillDefault
Selection.AutoFill Destination:=ws.Range("A6:" & Cells(6,
Columns.Count).End(xlToLeft).Address & ""), Type:=xlFillDefault

'ws.Range("A6:EY6").Select

ws.Range("A6:" & Cells(6, Columns.Count).End(xlToLeft).Address &
"").Select

End If
Next
--
Thanks