+ Reply to Thread
Results 1 to 6 of 6

VBA - runtime error 94, invalid use of null

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBA - runtime error 94, invalid use of null

    Hi There

    I've been using this macro that allows me to select multiple items in a drop down list

    Option Explicit
    Public Prior As String
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Author:    Jerry Beaucaire
    'Date:      10/2/2009, 8/17/2010
    'Summary:   These two macros create a multi-choice dropbox
    '           This version allows each option to be selected only once
    If Target.Count > 1 Then Exit Sub
    Application.EnableEvents = False
        If Not Intersect(Target, Range("E:E")) Is Nothing Then
            If Target <> "" Then
                If Prior <> "" Then
                    If InStr(Prior, Target) > 0 Then
                        Application.Undo
                    Else
                        Target = Target.Text & "," & Prior
                        Prior = Target
                    End If
                End If
            Else
                Prior = ""
            End If
        End If
    Application.EnableEvents = True
    End Sub
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Prior = Target.Text
    End Sub
    When I run debug it says that there is something to do with the Prior=Target.Text line. I'm a bit out of my depth here - how do I go about debugging this? I've attached my spreadsheet as an example. To get the error to occur, simply continue using the heading that states 'tax concession sought' selecting different items. It sometimes happens straight away, and other times it doesn't happen for a while, but eventually it does...

    Register Null Error.xlsm

    Thanks in advance

    Arneld

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: VBA - runtime error 94, invalid use of null

    dude you need to make a selection in c column for it to work
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    06-06-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA - runtime error 94, invalid use of null

    dude you need to make a selection in c column for it to work
    Of course, but regardless of that, the error still occurred. Cheers for your response anyway!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA - runtime error 94, invalid use of null

    Hello Arneld,

    Try this change to the code...
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If IsNull(Target.Text) Then Target.Value = ""
        Prior = Target.Value
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA - runtime error 94, invalid use of null

    I see, I can get that exact error if I accidentally select more than one cell on the sheet at a time. Try this correction:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Cells.Count > 1 Then Exit Sub
        Prior = Target(1).Text
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    06-06-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA - runtime error 94, invalid use of null

    It's working perfectly now. Thank you so much for your help!

+ 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