Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VB autofill problem 2

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
The following code only works when I activate and select the workbook and sheet it applies to.

Workbooks(sWorkbookToSort).Sheets(sSheetToSort).Range("B2:C2").AutoFill Destination:=Range(Cells(2, 2), Cells(iMaxRow, 3)), Type:=xlFillDefault

How could I get around that?
 




Hi,

fully refrence ALL ranges...
Code:
With Workbooks(sWorkbookToSort).Sheets(sSheetToSort)
    .Range("B2:C2").AutoFill _
        Destination:=[red][b].[/b][/red]Range(Cells(2, 2), _
        Cells(iMaxRow, 3)), _
        Type:=xlFillDefault
End With


Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 
Skip, thanks for the response. I thought I responded to your response but must have clicked the wrong button or something. I'm still having a problem.

This works:
Code:
Workbooks(sWorkbookToSort).Sheets(sSheetToSort).Activate
Workbooks(sWorkbookToSort).Sheets(sSheetToSort).Select
With Workbooks(sWorkbookToSort).Sheets(sSheetToSort)
    .Range("B2:C2").AutoFill _
        Destination:=.Range(Cells(2, 2), _
        Cells(iMaxRow, 3)), _
        Type:=xlFillDefault
End With

This does not work:
Code:
With Workbooks(sWorkbookToSort).Sheets(sSheetToSort)
    .Range("B2:C2").AutoFill _
        Destination:=.Range(Cells(2, 2), _
        Cells(iMaxRow, 3)), _
        Type:=xlFillDefault
End With

I believe I am referencing all ranges now, but something is still not working. I get an error: "runtime error '1004' Application-defined or object-defined error." Any advice?
 
And this ?
Code:
With Workbooks(sWorkbookToSort).Sheets(sSheetToSort)
    .Range("B2:C2").AutoFill _
        Destination:=.Range([!].[/!]Cells(2, 2), _
        [!].[/!]Cells(iMaxRow, 3)), _
        Type:=xlFillDefault
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ahhh shoot, that was it. I should've figured that out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top