Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have found out the last active row by code
VB
lastRow = FPWorkbook.Sheets(13).Cells(FPWorkbook.Sheets(13).Rows.Count, "B").End(xlUp).Row

I have tried two methods(both xlFillSeries and xlFillDefault), but not able to fill the index number from Cell A2 to last active row. Below is the code I have tried

VB
FPWorkbook.Sheets(13).Range("A2").AutoFill Destination:=FPWorkbook.Sheets(13).Range("A2:A" & lastRow), Type:=xlFillSeries

FPWorkbook.Sheets(13).Cells(2, 1).AutoFill Destination:=FPWorkbook.Sheets(13).Range("A2:A" & lastRow), Type:=xlFillDefault


Both these didn't work. Please help here

PS: FPWorkBook is my workbook object. I am currently accessing that sheet from another Workbook.
Posted
Updated 4-Sep-15 11:45am
v2

Here's the Excel macro I use to do an indexing on an entire spreadsheet:
Sub IndexSpreadsheetEntire()
   Dim rng As Range
     With ActiveSheet
       Set rng = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
     End With
       Set rng = rng.Offset(-1, -1)
                  rng(1) = 1
                  rng(2) = 2
           rng(1).Resize(2, 1).AutoFill rng
End Sub

The use of rng( ) sets up concommitant cell value inputs for the AutoFill to scope the entire sheet. Fiddling with the offsets allows the user to change the origin of the array.
 
Share this answer
 
This line looks pretty complicated
VB
lastRow = FPWorkbook.Sheets(13).Cells(FPWorkbook.Sheets(13).Rows.Count, "B").End(xlUp).Row

I would simplify with
VB
lastRow = FPWorkbook.Sheets(13).UsedRange.RowS.Count
 
Share this answer
 
Comments
arunkx 7-Sep-15 1:26am    
Thanks. But this was not the answer to my question though

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900