Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Plz,
I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count "1").End(xlUp).Row May be its because of the "1" ??? Thanks -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I think it is, that should be an integer.
Also, if accessing the active workbook, VBA maintains a pointer to that, so you don't need to go through the workbooks collection. And similarly with the active sheet, which also can only be in the active workbook Try LastRow = ActiveSheet.Cells(Rows.Count,1).End(xlUp).Row -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "ajliaks " wrote in message ... Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I think you can have an activesheet in every open workbook:
Option Explicit Sub testme() Dim wkbk As Workbook Dim iCtr As Long For iCtr = 1 To 3 Workbooks.Add 1 ActiveSheet.Name = "hi there" & iCtr Next iCtr For Each wkbk In Workbooks With wkbk.ActiveSheet MsgBox .Name & "--" & .Parent.Name End With Next wkbk End Sub Bob Phillips wrote: I think it is, that should be an integer. Also, if accessing the active workbook, VBA maintains a pointer to that, so you don't need to go through the workbooks collection. And similarly with the active sheet, which also can only be in the active workbook Try LastRow = ActiveSheet.Cells(Rows.Count,1).End(xlUp).Row -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "ajliaks " wrote in message ... Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I think Bob gave you the answer, but you could use "A", too:
And I think I'd do: Dim LastRow As Long Just in case it's a big number (32k). Dim LastRow As Long with activesheet LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row end with and one mo workbooks(activeworkbook.name) is equivalent to activeworkbook "ajliaks <" wrote: Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Which is better IMO
Bob "Dave Peterson" wrote in message ... I think Bob gave you the answer, but you could use "A", too: And I think I'd do: Dim LastRow As Long Just in case it's a big number (32k). Dim LastRow As Long with activesheet LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row end with and one mo workbooks(activeworkbook.name) is equivalent to activeworkbook "ajliaks <" wrote: Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dim lngLastRow As Long
lngLastRow = ActiveSheet.UsedRange.Rows.Count -- Regards, Bill "ajliaks " wrote in message ... Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That would give the number of rows in the used range--not always the last used
row. If your data were in A99:A100, you'd get 2. Maybe Dim lngLastRow As Long with activesheet lngLastRow = .UsedRange.rows(.usedrange.rows.count).row end with just in case?? Bill Renaud wrote: Dim lngLastRow As Long lngLastRow = ActiveSheet.UsedRange.Rows.Count -- Regards, Bill "ajliaks " wrote in message ... Plz, I am trying to use this, but getting error! I need to get the last active row in the active sheet Dim LastRow As Integer LastRow = Workbooks(ActiveWorkbook.Name).Worksheets(ActiveSh eet).Cells(Rows.Count, "1").End(xlUp).Row May be its because of the "1" ??? Thanks. --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Type mismatch... | Excel Discussion (Misc queries) | |||
Type Mismatch | Excel Programming | |||
Type Mismatch | Excel Programming | |||
Type mismatch | Excel Programming | |||
Type Mismatch | Excel Programming |