Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set Public Variable on Open

Can you set a variable when a workbook opens? I have been trying to
set a LstRow as long variabel to be used by multiple modules on open
and I cna not seem to get it to work. Here is what I have in the
workbook module. I have many macros that call out for LstRow and
assumed it woudl be easier to set it in one shot and then call it crom
each of the macros going forward.

Option Explicit
Public LstRow As Long

Private Sub Workbook_Open()
LstRow = Sheet1.UsedRange.Rows.Count
End Sub

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Set Public Variable on Open

Dim r As Range
Set r = Sheets("Sheet1").UsedRange
nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)
--
Gary''s Student - gsnu200903


"jlclyde" wrote:

Can you set a variable when a workbook opens? I have been trying to
set a LstRow as long variabel to be used by multiple modules on open
and I cna not seem to get it to work. Here is what I have in the
workbook module. I have many macros that call out for LstRow and
assumed it woudl be easier to set it in one shot and then call it crom
each of the macros going forward.

Option Explicit
Public LstRow As Long

Private Sub Workbook_Open()
LstRow = Sheet1.UsedRange.Rows.Count
End Sub

Thanks,
Jay

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set Public Variable on Open

On Sep 11, 12:20*pm, Gary''s Student
wrote:
Dim r As Range
Set r = Sheets("Sheet1").UsedRange
nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)
--
Gary''s Student - gsnu200903



"jlclyde" wrote:
Can you set a variable when a workbook opens? *I have been trying to
set a LstRow as long variabel to be used by multiple modules on open
and I cna not seem to get it to work. *Here is what I have in the
workbook module. *I have many macros that call out for LstRow and
assumed it woudl be easier to set it in one shot and then call it crom
each of the macros going forward.


Option Explicit
Public LstRow As Long


Private Sub Workbook_Open()
* * LstRow = Sheet1.UsedRange.Rows.Count
End Sub


Thanks,
Jay- Hide quoted text -


- Show quoted text -


This will set a variable as public to be used in multiple macros?
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Set Public Variable on Open

Just be sure to DIM it in a standard module ABOVE any subs or functions and
DIM it as Public:

Public nLastRow as Long

By DIMming it OUTSIDE any subs (normal or event) it will be both public and
static
--
Gary''s Student - gsnu200903


"jlclyde" wrote:

On Sep 11, 12:20 pm, Gary''s Student
wrote:
Dim r As Range
Set r = Sheets("Sheet1").UsedRange
nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)
--
Gary''s Student - gsnu200903



"jlclyde" wrote:
Can you set a variable when a workbook opens? I have been trying to
set a LstRow as long variabel to be used by multiple modules on open
and I cna not seem to get it to work. Here is what I have in the
workbook module. I have many macros that call out for LstRow and
assumed it woudl be easier to set it in one shot and then call it crom
each of the macros going forward.


Option Explicit
Public LstRow As Long


Private Sub Workbook_Open()
LstRow = Sheet1.UsedRange.Rows.Count
End Sub


Thanks,
Jay- Hide quoted text -


- Show quoted text -


This will set a variable as public to be used in multiple macros?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Set Public Variable on Open

On Sep 11, 12:47*pm, Gary''s Student
wrote:
Just be sure to DIM it in a standard module ABOVE any subs or functions and
DIM it as Public:

Public nLastRow as Long

By DIMming it OUTSIDE any subs (normal or event) it will be both public and
static
--
Gary''s Student - gsnu200903



"jlclyde" wrote:
On Sep 11, 12:20 pm, Gary''s Student
wrote:
Dim r As Range
Set r = Sheets("Sheet1").UsedRange
nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)
--
Gary''s Student - gsnu200903


"jlclyde" wrote:
Can you set a variable when a workbook opens? *I have been trying to
set a LstRow as long variabel to be used by multiple modules on open
and I cna not seem to get it to work. *Here is what I have in the
workbook module. *I have many macros that call out for LstRow and
assumed it woudl be easier to set it in one shot and then call it crom
each of the macros going forward.


Option Explicit
Public LstRow As Long


Private Sub Workbook_Open()
* * LstRow = Sheet1.UsedRange.Rows.Count
End Sub


Thanks,
Jay- Hide quoted text -


- Show quoted text -


This will set a variable as public to be used in multiple macros?- Hide quoted text -


- Show quoted text -


When I go to another module and run the macros that call out the
LstRow, LstRow is = 0. Even though it is set when the workbook
opens. Why is this and how do I get the LstRow to = the last used
Range.row for all macros and functions?

Thanks,
Jay`
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
Public Variables Jerry McNabb Excel Discussion (Misc queries) 0 February 24th 08 01:26 AM
Public Password Excel 2003 - SPB Excel Discussion (Misc queries) 2 May 23rd 07 11:08 PM
Using A Public Function / carl Excel Worksheet Functions 1 April 6th 06 09:13 PM
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
open file (as variable) from macro d chaps Excel Discussion (Misc queries) 1 March 14th 05 11:57 PM


All times are GMT +1. The time now is 11:25 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"