Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default VBA question - Type Mismatch

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default VBA question - Type Mismatch

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch... George[_4_] Excel Discussion (Misc queries) 7 December 19th 07 12:20 PM
Type Mismatch Rockee052[_60_] Excel Programming 4 March 7th 04 12:12 AM
Type Mismatch Edgar[_3_] Excel Programming 4 February 13th 04 03:55 PM
Type mismatch Steve Garman Excel Programming 0 February 5th 04 07:39 AM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM


All times are GMT +1. The time now is 03:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"