Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Code not working

I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Code not working

Press Alt + F11 to open the VB editor. In the Projects pane at the upper
left side of the screen, double click on ThisWorkbook and paste the code
into the code window that opens. Be sure that the title bar show
ThisWorkbook(Code) when you paste.

Private Sub Workbook_Open()
Dim Lrow As Long
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub




"JMay" wrote in message
...
I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below
is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Code not working

P.S. If you still have this in another code module, delete it.


"JMay" wrote in message
...
I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below
is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Code not working

1) create a Module in the Visual Basic Editor (VBE)
- INSERT MODULE

2) put the following line of code at the top of the module in order to make
it's SCOPE so that all modules will know it's value...
Public Lrow As Long

3) in the 'ThisWorkbook' module, put the following code...
Private Sub Workbook_Open()
Lrow = Worksheets("Sheet2").Cells.SpecialCells(xlLastCell ).Row
End Sub

4) in the worksheet "Sheets2" module, put the following code...
Private Sub Worksheet_Change(ByVal Target As Range)
Lrow = Worksheets("Sheet2").Cells.SpecialCells(xlLastCell ).Row
End Sub

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"JMay" wrote:

I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Code not working

Thanks Gary;;;

"Gary Brown" wrote:

1) create a Module in the Visual Basic Editor (VBE)
- INSERT MODULE

2) put the following line of code at the top of the module in order to make
it's SCOPE so that all modules will know it's value...
Public Lrow As Long

3) in the 'ThisWorkbook' module, put the following code...
Private Sub Workbook_Open()
Lrow = Worksheets("Sheet2").Cells.SpecialCells(xlLastCell ).Row
End Sub

4) in the worksheet "Sheets2" module, put the following code...
Private Sub Worksheet_Change(ByVal Target As Range)
Lrow = Worksheets("Sheet2").Cells.SpecialCells(xlLastCell ).Row
End Sub

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"JMay" wrote:

I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Code not working

How do you know it is not working?

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
MsgBox Lrow
End Sub

Gives me a message of last row number in Sheet2 which just happens to be 32

But you won't get an update as you fill-in rows in column A unless you run
again.

To keep updating Lrow for use somewhere you could add event code to Sheet2

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Lrow As Long
Lrow = Cells(Rows.Count, "A").End(xlUp).Row
MsgBox Lrow
End Sub


Gord Dibben MS Excel MVP

On Tue, 16 Mar 2010 11:14:01 -0700, JMay
wrote:

I need to capture the Last Row number as soon as the WB opens; And as the
sheet2 Column A cells are filled-in have the variable Lrow furnish an
up-to-date
value, representing the last non-blank row in Col A of Sheet2. The below is
not working; Can yo suggest a better way?

TIA,

Dim Lrow As Long
Private Sub Workbook_Open()
Lrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End Sub


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
code is not working. Heera Chavan[_2_] Excel Programming 5 November 10th 09 04:26 PM
code not working Moh Excel Programming 5 December 18th 07 08:21 AM
Code is not working....please take a look!!! tratliff[_12_] Excel Programming 5 August 24th 04 05:45 PM
why this code not working tj Excel Programming 0 September 2nd 03 07:14 PM
why this code not working Bernie Deitrick[_2_] Excel Programming 0 September 2nd 03 05:08 PM


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