Get Cell Value in Excel VBA

Keith

Registered User.
Local time
Today, 09:06
Joined
May 21, 2000
Messages
129
I wish to check the value of a cell when a form is opened. I have spent a long time trying to find a solution.
The procedure that I have is,

Private Sub UserForm_Activate()
Dim x As Integer
x = Worksheets("Data").Range("P1:P1").Value
Debug.Print x

End Sub



I get the error ' Line is not an executable statement'. any suggestions please
 
Try changing this:

x = Worksheets("Data").Range("P1:P1").Value


to this:

x = Worksheets("Data").Range("P1").Value
 
Thanks for the reply Bob, I've tried your suggestion but get the same error.
What I am trying to do is allow the user to add to a list of names but the list cannot contain more than 20 names. When the User Form is opened I want to check that list contains less than 20 names, if so allow the user to add a name. The cell "P1" contains a count of the names in the list.
 
Can you post your spreadsheet so we can check it out?
 
Can you post your spreadsheet so we can check it out?

Thanks Bob I've Solved it.

Code:
Private Sub UserForm_Activate()
    Dim NewRow As Integer

    NewRow = Worksheets("Data").Range("$P$1").Value

    If NewRow = 20 Then
        Call MsgBox("The maximum number has been reached", vbExclamation, Application.Name)
        frmNewName.Hide
    End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom