+ Reply to Thread
Results 1 to 5 of 5

Thread: vba range issue

  1. #1
    Registered User
    Join Date
    07-30-2009
    Location
    melbourne, AUS
    MS-Off Ver
    Excel 2003
    Posts
    34

    vba range issue

    hello
    i have a code that searches column B for data entered in textbox, when the data is located it highlights active row yellow, i then added the following code so that when i changed from highlighted row the row changed back to no fill. it worked but now i can not cut and paste within the sheet? can this be fixed.

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Range("$B:$I").Interior.ColorIndex = xlNone
        Intersect(Target.EntireRow, Range("$B:$I")).Interior.ColorIndex = xlNone
        Range("B5:I5").Interior.ColorIndex = 34
        Range("B9:I9").Interior.ColorIndex = 35
    End Sub
    Last edited by rylo; 07-31-2009 at 12:17 AM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,493

    Re: vba range issue

    Hello waltron,

    Welcome to the Forum!

    What lead you to believe this routine is causing the problem?
    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!)

  3. #3
    Registered User
    Join Date
    07-30-2009
    Location
    melbourne, AUS
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: vba range issue

    g'day Leith

    when i removed the above mentioned code i could cut and paste. i have another code (posted below) that also stops working when this code is active. i get a run time error "1004" "paste method of worksheet failed" i can't put my finger on it?
    Code:
      Sub addjob()
    
        Rows("7:7").Select
        Selection.Copy
        Rows("102:102").Select
        ActiveSheet.Paste
        Rows("11:102").Select
        Application.CutCopyMode = False
        Selection.Sort Key1:=Range("C11"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        Rows("7:7").Select
        Selection.ClearContents
        Range("B7").Select
        ActiveWorkbook.save
    End Sub
    Cheers.
    Last edited by Leith Ross; 07-31-2009 at 02:27 AM.

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

    Re: vba range issue

    Hello waltron,

    I don't know why your workbook is all buggered up but give this a try.
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim Rng As Range
        Range("$B:$I").Interior.ColorIndex = xlNone
          Set Rng = Intersect(Target.EntireRow, Range("$B:$I"))
            If Not Rng Is Nothing Then
               Rng.Interior.ColorIndex = xlNone
               Range("B5:I5").Interior.ColorIndex = 34
               Range("B9:I9").Interior.ColorIndex = 35
            End If
    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
    Registered User
    Join Date
    07-30-2009
    Location
    melbourne, AUS
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: vba range issue

    morning,

    Good 1 leith it seems to have fixed my issue, thanks for your help I'm still learning this whole VBA caper. Much appreciated.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0