+ Reply to Thread
Results 1 to 2 of 2

Clear contents based on value in another cell

  1. #1
    Registered User
    Join Date
    11-24-2010
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Clear contents based on value in another cell

    I have a macro that works, but I know isn't the most efficient way to do it. I want to search column G starting at row 11 for "GT123" or "GT456" and clear the contents of cells J through AI. There will be 600 to 700 rows of data everytime I run this report. What is a better way of doing this? Thanks for any help you can offer.

    Dim wks As Worksheet
    Dim rngToSearch As Range
    Dim rngFirst As Range
    Dim rngCurrent As Range

    Set wks = ActiveSheet
    Set rngToSearch = wks.Range("G11:G700")
    Set rngCurrent = rngToSearch.Find("GT*", , , xlWhole)
    If Not rngCurrent Is Nothing Then
    Set rngFirst = rngCurrent
    Do
    rngCurrent.Offset(0, 3).ClearContents
    rngCurrent.Offset(0, 4).ClearContents
    rngCurrent.Offset(0, 5).ClearContents
    rngCurrent.Offset(0, 6).ClearContents
    rngCurrent.Offset(0, 7).ClearContents
    rngCurrent.Offset(0, 8).ClearContents
    rngCurrent.Offset(0, 9).ClearContents
    rngCurrent.Offset(0, 10).ClearContents
    rngCurrent.Offset(0, 11).ClearContents
    rngCurrent.Offset(0, 12).ClearContents
    rngCurrent.Offset(0, 13).ClearContents
    rngCurrent.Offset(0, 14).ClearContents
    rngCurrent.Offset(0, 15).ClearContents
    rngCurrent.Offset(0, 16).ClearContents
    rngCurrent.Offset(0, 17).ClearContents
    rngCurrent.Offset(0, 18).ClearContents
    rngCurrent.Offset(0, 19).ClearContents
    rngCurrent.Offset(0, 20).ClearContents
    rngCurrent.Offset(0, 21).ClearContents
    rngCurrent.Offset(0, 22).ClearContents
    rngCurrent.Offset(0, 23).ClearContents
    rngCurrent.Offset(0, 24).ClearContents
    rngCurrent.Offset(0, 25).ClearContents
    rngCurrent.Offset(0, 26).ClearContents
    rngCurrent.Offset(0, 27).ClearContents
    rngCurrent.Offset(0, 28).ClearContents

    Set rngCurrent = rngToSearch.FindNext(rngCurrent)
    Loop Until rngCurrent.Address = rngFirst.Address
    End If

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Clear contents based on value in another cell

    Please wrap your code in code tags, before the moderators get you...

    Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.

    Cheers

    Then try this
    Please Login or Register  to view this content.

    Hope this helps
    Last edited by Marcol; 12-01-2010 at 12:26 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ 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