+ Reply to Thread
Results 1 to 7 of 7

Compile error: Method or data member not found.

Hybrid View

  1. #1
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Compile error: Method or data member not found.

    Trying to run the code below on a sheet but keep getting compile error. In bold is what is erroring (is that a real word?)

    My aim is to have it so a box (5,2) has either a Y or N entry.
    If it is Y then (9,8) = (10,31) on this page.....this works
    Also if Y then another cell (9,3) = value in (1,1) from another page in this workbook (Main Data)

    Where have I gone wrong??

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Cells(5, 2) = "N" Then
    Cells(9, 8) = "0"
    ElseIf Cells(5, 2) = "Y" Then
    Cells(9, 8) = Cells(10, 31)
    ElseIf Cells(5, 2) = "Y" Then
    Worksheet("GPS Mapping").Cells(9, 3).Value = ThisWorkbook.Worksheet("Main Data").Cells(1, 1).Value
    
    
    
    End If
    End
    
    End Sub

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Compile error: Method or data member not found.

    Should be "Worksheets" and not "Worksheet".

  3. #3
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Re: Compile error: Method or data member not found.

    omg....can't see the wood for the trees

    Thanks

  4. #4
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Re: Compile error: Method or data member not found.

    So now I have got past that little oversight the new code no longer gives compile errors.....but it does not return the number from Main Data cell (7,6), have I missed something else?
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Cells(5, 2) = "N" Then
    Cells(9, 8) = "0"
    If Cells(5, 2) = "Y" Then
    Cells(9, 3) = Worksheets("Main Data").Cells(7, 6).Value
    ElseIf Cells(5, 2) = "Y" Then
    Cells(9, 8) = Cells(10, 31)
    End If
    End If
    End Sub

  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Compile error: Method or data member not found.

    Try this.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Cells(5, 2).Value = "N" Then
        Cells(9, 8).Value = "0"
        If Cells(5, 2).Value = "Y" Then
            Cells(9, 3).Value = Worksheets("Main Data").Cells(7, 6).Value
        ElseIf Cells(5, 2).Value = "Y" Then
            Cells(9, 8).Value = Cells(10, 31).Value
        End If
    End If
    End Sub

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Compile error: Method or data member not found.

    Both your conditions are the same
    If Cells(5, 2).Value = "Y" Then
    ...
    ElseIf Cells(5, 2).Value = "Y" Then

  7. #7
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Re: Compile error: Method or data member not found.

    I understand that both of the conditions are the same, have just added that extra elseIf and is OK now, thanks Stephen and Stepsahead

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1