Consulting

Results 1 to 9 of 9

Thread: Moving highlight scroll bar

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Moving highlight scroll bar

    Hello,

    I use this code built into a sheet to have a moving highlight when I scroll up and down rows. However, can I just place something similar to this at the end of my macro to say on the current worksheet, have a moving highlight when scrolling?

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.Interior.ColorIndex = xlNone
    Target.EntireRow.Interior.ColorIndex = 35
    End Sub
    Last edited by Aussiebear; 04-16-2014 at 03:28 PM. Reason: Added Code tags to submitted code

  2. #2
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Right now to use that code in a sheet I right click "Sheet 1" and say view code and paste the above code in the macro and that does the trick. However is there a vba macro for the process of right clicking sheet 1, saying view code, and pasting the selected code, so I don't have to do it manually every time? Can this step the last step in a large macro I have?

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Try recording a macro, then adjust the code if necessary.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    That's actually quite neat.

    Do it once, save your workbook as a macro workbook, and then the code will be saved. You won't have to insert it everytime.

    I presume that your saving your workbook as a normal xlsx book, so therefore the code actually gets wiped every time. Save it as a xlsm and then you'll be fine.

    (assuming that your using Excel 2007 onwards)
    The same applies in earlier versions, just the file extension is different.

  5. #5
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    I tried recording it and it doesn't work. I don't run this macro on the same workbook everytime, therefore saving this as a macro workbook with the code wont work because its a new workbook everytime.

  6. #6
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    I tried using this code in my macro but it doesn't seem to work. Can we slightly alter it to make it work?

    Sub Test()
    Worksheet_SelectionChange(ByVal Target As Range)
    Cells.Interior.ColorIndex = xlNone
    Target.EntireRow.Interior.ColorIndex = 35
    End Sub

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    You have to use a workbook event not a worksheet event

    In "thisworkbook':

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
       sh.Cells.Interior.ColorIndex = xlNone
       Target.EntireRow.Interior.ColorIndex = 35
    End Sub

  8. #8
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Ok so is there anyway to integrate the above macro into my greater macro? I would I call the above to run?

    Sub Spread()
    Call Spreadsheet
    Call PasteValuesinSheet
    Call NameEarlyMidLate
    Call OpenEarlyMidLateInput
    Call CopyInput
    Call CloseInputsheet
    Call SelectBook1
    Call Formula
    Call FormulaCallDate
    Call Formula2
    Call NameColumnsOandP
    Call ExpandP
    Call Workbook_SheetSelectionChange ????????
    End Sub

  9. #9
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    You don't Call an Event triggered Sub. It runs whenever the Event occurs. You could say "The Event 'Calls' the sub."

    In order to have the the Sub respond to Events in all Workbooks, you must write it as an Application Event, and that means creating an Event Class Module.

    It might be easier just to put the Workbook Event Sub in all the Workbooks it has to work in. Of course, this wouldn't be a good idea if you want it to work in new workbooks.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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