Consulting

Results 1 to 5 of 5

Thread: Code Wont' Run in 97

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Code Wont' Run in 97

    Someone near and dear wrote this code, but it doesn't run in 97.


    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i               As Long
    Dim LastRow         As Long
    Dim Cel             As Range
        If Target.Column = 3 Or Target.Column = 4 Then
            LastRow = Range("A65536").End(xlUp).Row
            For i = 2 To LastRow
                Set Cel = Sheet2.Range("A:A").Find(What:=Range("C" & i).Text, _
                    LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
                If Cel Is Nothing Then
                    Range("C" & i).Interior.ColorIndex = xlNone
                Else
                    Range("C" & i).Interior.ColorIndex = _
    Sheet2.Range("A" & Cel.Row).Interior.ColorIndex
                End If
            Next i
            For i = 2 To LastRow
                Set Cel = Sheet2.Range("B:B").Find(What:=Range("D" & i).Text, _
                    LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
                If Cel Is Nothing Then
                    Range("D" & i).Interior.ColorIndex = xlNone
                Else
                    Range("D" & i).Interior.ColorIndex = _
    Sheet2.Range("B" & Cel.Row).Interior.ColorIndex
                End If
            Next i
        End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim i               As Long
    Dim LastRow         As Long
        If Intersect(Target, Range("A1,C1:D1")) Is Nothing Then
            Exit Sub
        End If
    Application.ScreenUpdating = False
        Application.EnableEvents = False
    Range("C:D").NumberFormat = "@"
    LastRow = Sheet2.Range("A65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("C:C").Replace What:=Sheet2.Range("A" & i).Text, _
                Replacement:=Application.WorksheetFunction.Rept("a", i), LookAt:=xlWhole
        Next i
    LastRow = Sheet2.Range("B65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("D:D").Replace What:=Sheet2.Range("B" & i).Text, _
                Replacement:=Application.WorksheetFunction.Rept("a", i), LookAt:=xlWhole
        Next i
    Select Case Target.Column
            Case Is = 1
                Range("sfw").Sort Key1:=Range("A2"), Order1:=xlAscending, _
                    Key2:=Range("C2"), Order2:=xlAscending, _
                    Key3:=Range("D2"), Order3:=xlAscending, _
                    Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
                    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
                    DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
            Case Is = 3
                Range("sfw").Sort Key1:=Range("C2"), Order1:=xlAscending, _
                    Key2:=Range("A2"), Order2:=xlAscending, _
                    Key3:=Range("D2"), Order3:=xlAscending, _
                    Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
                    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
                    DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
            Case Is = 4
                Range("sfw").Sort Key1:=Range("D2"), Order1:=xlAscending, _
                    Key2:=Range("A2"), Order2:=xlAscending, _
                    Key3:=Range("C2"), Order3:=xlAscending, _
                    Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
                    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
                    DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
        End Select
        LastRow = Sheet2.Range("A65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("C:C").Replace What:=Application.WorksheetFunction.Rept("a", i), _
                Replacement:=Sheet2.Range("A" & i).Text, LookAt:=xlWhole
        Next i
    LastRow = Sheet2.Range("B65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("D:D").Replace What:=Application.WorksheetFunction.Rept("a", i), _
                Replacement:=Sheet2.Range("B" & i).Text, LookAt:=xlWhole
        Next i
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    ~Anne Troy

  2. #2
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    This describes the problem, but darned if I can fix it.
    http://www.mrexcel.com/archive2/63900/73999.htm
    ~Anne Troy

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Anne,

    I think that if you run a find/replace on your code, and replace this:

    , DataOption1:=xlSortNormal, _ 
            DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
    With nothing (blank) it should work... You've got about 3 instances of it in there, but 97 doesn't support those properties.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Sorry, missed one. OrderCustom has to go as well:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim i               As Long
        Dim LastRow         As Long
        Dim Cel             As Range
        If Target.Column = 3 Or Target.Column = 4 Then
            LastRow = Range("A65536").End(xlUp).Row
            For i = 2 To LastRow
                Set Cel = Sheet2.Range("A:A").Find(What:=Range("C" & i).Text, _
                LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
                If Cel Is Nothing Then
                    Range("C" & i).Interior.ColorIndex = xlNone
                Else
                    Range("C" & i).Interior.ColorIndex = _
    Sheet2.Range("A" & Cel.Row).Interior.ColorIndex
                End If
            Next i
            For i = 2 To LastRow
                Set Cel = Sheet2.Range("B:B").Find(What:=Range("D" & i).Text, _
                LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
                If Cel Is Nothing Then
                    Range("D" & i).Interior.ColorIndex = xlNone
                Else
                    Range("D" & i).Interior.ColorIndex = _
    Sheet2.Range("B" & Cel.Row).Interior.ColorIndex
                End If
            Next i
        End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim i               As Long
        Dim LastRow         As Long
        If Intersect(Target, Range("A1,C1:D1")) Is Nothing Then
            Exit Sub
        End If
    Application.ScreenUpdating = False
        Application.EnableEvents = False
    Range("C:D").NumberFormat = "@"
    LastRow = Sheet2.Range("A65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("C:C").Replace What:=Sheet2.Range("A" & i).Text, _
            Replacement:=Application.WorksheetFunction.Rept("a", i), LookAt:=xlWhole
        Next i
    LastRow = Sheet2.Range("B65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("D:D").Replace What:=Sheet2.Range("B" & i).Text, _
            Replacement:=Application.WorksheetFunction.Rept("a", i), LookAt:=xlWhole
        Next i
    Select Case Target.Column
        Case Is = 1
            Range("sfw").Sort Key1:=Range("A2"), Order1:=xlAscending, _
            Key2:=Range("C2"), Order2:=xlAscending, _
            Key3:=Range("D2"), Order3:=xlAscending, _
            Header:=xlNo, MatchCase:=False, _
            Orientation:=xlTopToBottom
        Case Is = 3
            Range("sfw").Sort Key1:=Range("C2"), Order1:=xlAscending, _
            Key2:=Range("A2"), Order2:=xlAscending, _
            Key3:=Range("D2"), Order3:=xlAscending, _
            Header:=xlNo, MatchCase:=False, _
            Orientation:=xlTopToBottom
        Case Is = 4
            Range("sfw").Sort Key1:=Range("D2"), Order1:=xlAscending, _
            Key2:=Range("A2"), Order2:=xlAscending, _
            Key3:=Range("C2"), Order3:=xlAscending, _
            Header:=xlNo, MatchCase:=False, _
            Orientation:=xlTopToBottom
        End Select
        LastRow = Sheet2.Range("A65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("C:C").Replace What:=Application.WorksheetFunction.Rept("a", i), _
            Replacement:=Sheet2.Range("A" & i).Text, LookAt:=xlWhole
        Next i
    LastRow = Sheet2.Range("B65536").End(xlUp).Row
        For i = 2 To LastRow
            Range("D:D").Replace What:=Application.WorksheetFunction.Rept("a", i), _
            Replacement:=Sheet2.Range("B" & i).Text, LookAt:=xlWhole
        Next i
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub

    Let me know,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Our YIM discussion, LOL.
    Ken Puls: posted 2 replies
    Dreamboat: THANKS
    Ken Puls: Don't thank me till it works!
    Ken Puls: lol
    Dreamboat: k
    Dreamboat: You're the freaking bomb, dude.
    Ken Puls: I take it it works?
    Dreamboat: ubet
    Dreamboat: Thanks a ton.
    ~Anne Troy

Posting Permissions

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