Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default questions about Dim


Hi

I want to make the lastrow of sheet1 column A common knowledge between
my macros. Reason being is i want to refer the the lastrow a lot of
times

I thought maybe public sub would help this is my code

Public figs
' Count Rows in table
Dim lastRowpub As Long
lastRowpub = Worksheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row


It keeps coming up saying

Compile Error: Invalid Outside Procedure

and then highlights the (xlUp) part of the line


any ideas?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default questions about Dim

You need a sub

Public figs
Public lastRowpub As Long

Sub CountRows()
' Count Rows in table
lastRowpub = Worksheets("Sheet1").Cells(Rows.Count,"A").End(xlU p).Row
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"funkymonkUK"
wrote in message
...

Hi

I want to make the lastrow of sheet1 column A common knowledge between
my macros. Reason being is i want to refer the the lastrow a lot of
times

I thought maybe public sub would help this is my code

Public figs
' Count Rows in table
Dim lastRowpub As Long
lastRowpub = Worksheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row


It keeps coming up saying

Compile Error: Invalid Outside Procedure

and then highlights the (xlUp) part of the line


any ideas?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile:

http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default questions about Dim


thanks

so would I need to run this sub each time before using the lastrow ?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default questions about Dim

Yep, in fact it would be better as a function and call the function.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"funkymonkUK"
wrote in message
...

thanks

so would I need to run this sub each time before using the lastrow ?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile:

http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default questions about Dim


how i do that?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default questions about Dim

Function lastRowpub() As Long
' Count Rows in table
lastRowpub = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
End Function

You can use this function as follows:

set rng = cells(lasrRowpub(),"a")

HTH
--
AP

"funkymonkUK" a
écrit dans le message de
...

how i do that?


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile:

http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=516165



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
Answers to questions posing more questions in a workbook sbelle1 Excel Worksheet Functions 2 August 8th 09 01:02 AM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
Questions about ADO [email protected] Excel Programming 5 January 19th 05 02:01 AM
2 questions again steve Excel Programming 0 September 30th 03 12:03 AM
2 questions again john petty Excel Programming 0 September 29th 03 04:28 PM


All times are GMT +1. The time now is 04:14 PM.

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"