Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
UserForm_Initialize error
I am using an example in a book and it says to add <LastRow = FindLastRow to
the UserForm_Initialize event. As you can see I did, BUT I keep getting a "Variable not defined" rigth there. Help! Yes, I know it is probably very basic. Thank you! Private Sub UserForm_Initialize GetData LastRow = FindLastRow Dim cItem As Range With Me.cboVend For Each cItem In wksLookupLists.Range("VendorList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With With Me.cboRan For Each cItem In wksLookupLists.Range("RanchIDList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With txtDate.Value = Date End Sub -- Though daily learning, I LOVE EXCEL! Jennifer |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
UserForm_Initialize error
Jennifer,
I would assume "FindLastRow" is a function that determines the last row with data on a worksheet. LastRow calls the function, but the function has to exist someplace within your project. Get the function code from the book and add it to any general module. However, I don't see that "LastRow" is used within the initialize event, so why have it in there? Regards, Jim Cone San Francisco, USA "Jennifer" wrote in message ... I am using an example in a book and it says to add <LastRow = FindLastRow to the UserForm_Initialize event. As you can see I did, BUT I keep getting a "Variable not defined" rigth there. Help! Yes, I know it is probably very basic. Thank you! Private Sub UserForm_Initialize GetData LastRow = FindLastRow Dim cItem As Range With Me.cboVend For Each cItem In wksLookupLists.Range("VendorList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With With Me.cboRan For Each cItem In wksLookupLists.Range("RanchIDList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With txtDate.Value = Date End Sub -- Though daily learning, I LOVE EXCEL! Jennifer |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
UserForm_Initialize error
What would the function code look like?
The book went through a couple of differant steps. 1.Const LastRow = 20 2.Public LastRow As Long (it says it makes this dynamic) 3.Set the LastRow Variable by assing the following line to the UserForm_Iniitalize event: LastRow = FindLastRow Thanks for your help. "Jim Cone" wrote: Jennifer, I would assume "FindLastRow" is a function that determines the last row with data on a worksheet. LastRow calls the function, but the function has to exist someplace within your project. Get the function code from the book and add it to any general module. However, I don't see that "LastRow" is used within the initialize event, so why have it in there? Regards, Jim Cone San Francisco, USA "Jennifer" wrote in message ... I am using an example in a book and it says to add <LastRow = FindLastRow to the UserForm_Initialize event. As you can see I did, BUT I keep getting a "Variable not defined" rigth there. Help! Yes, I know it is probably very basic. Thank you! Private Sub UserForm_Initialize GetData LastRow = FindLastRow Dim cItem As Range With Me.cboVend For Each cItem In wksLookupLists.Range("VendorList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With With Me.cboRan For Each cItem In wksLookupLists.Range("RanchIDList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With txtDate.Value = Date End Sub -- Though daily learning, I LOVE EXCEL! Jennifer |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
UserForm_Initialize error
Jennifer,
If you know that the LastRow will never change, then you can use your line1: Const LastRow as Long =xx 'a number That line would replace line2: Public LastRow as Long However, if the last row with data changes then you need to call the function that determines the row... The example below requires you to specify the sheet from which the bottom row is to be extracted. You would call it like this... LastRow = FindLastRow(ActiveSheet) '============================================= ' FindLastRow() Function ' Aug 31, 2001 - Created by Jim Cone - San Francisco, USA ' Returns the number of the last worksheet row with data. ' If the sheet is blank it returns 0. '============================================= Function FindLastRow(ByRef TheSheet As Excel.Worksheet) As Long On Error GoTo NoRow If TheSheet.FilterMode Then TheSheet.ShowAllData FindLastRow = TheSheet.Cells.Find(what:="*", SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row Exit Function NoRow: FindLastRow = 0 End Function '============================================ "Jennifer" wrote in message ... What would the function code look like? The book went through a couple of differant steps. 1.Const LastRow = 20 2.Public LastRow As Long (it says it makes this dynamic) 3.Set the LastRow Variable by assing the following line to the UserForm_Iniitalize event: LastRow = FindLastRow Thanks for your help. "Jim Cone" wrote: Jennifer, I would assume "FindLastRow" is a function that determines the last row with data on a worksheet. LastRow calls the function, but the function has to exist someplace within your project. Get the function code from the book and add it to any general module. However, I don't see that "LastRow" is used within the initialize event, so why have it in there? Regards, Jim Cone San Francisco, USA "Jennifer" wrote in message ... I am using an example in a book and it says to add <LastRow = FindLastRow to the UserForm_Initialize event. As you can see I did, BUT I keep getting a "Variable not defined" rigth there. Help! Yes, I know it is probably very basic. Thank you! Private Sub UserForm_Initialize GetData LastRow = FindLastRow Dim cItem As Range With Me.cboVend For Each cItem In wksLookupLists.Range("VendorList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With With Me.cboRan For Each cItem In wksLookupLists.Range("RanchIDList") .AddItem cItem.Value .List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value Next End With txtDate.Value = Date End Sub -- Though daily learning, I LOVE EXCEL! Jennifer |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
UserForm_Initialize() | Excel Programming | |||
Calling (Function?) from Userform_Initialize to generate list of unique values for Combo box | Excel Programming | |||
Userform_Initialize event failing to be called | Excel Programming | |||
UserForm_Initialize | Excel Programming | |||
UserForm_Initialize? How to update. | Excel Programming |