+ Reply to Thread
Results 1 to 11 of 11

Search within a column and repeat the search until all items are found

Hybrid View

RANDY LIPOSKY Search within a column and... 01-06-2014, 01:13 PM
JOHN H. DAVIS Re: Search within a column... 01-06-2014, 01:36 PM
Leith Ross Re: Search within a column... 01-06-2014, 01:51 PM
RANDY LIPOSKY Re: Search within a column... 01-06-2014, 05:21 PM
JOHN H. DAVIS Re: Search within a column... 01-07-2014, 07:30 AM
RANDY LIPOSKY Re: Search within a column... 01-07-2014, 09:29 AM
JOHN H. DAVIS Re: Search within a column... 01-07-2014, 09:32 AM
RANDY LIPOSKY Re: Search within a column... 01-07-2014, 12:24 PM
RANDY LIPOSKY Re: Search within a column... 01-08-2014, 09:46 AM
RANDY LIPOSKY Re: Search within a column... 01-09-2014, 10:23 AM
RANDY LIPOSKY Re: Search within a column... 01-07-2014, 11:57 AM
  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Search within a column and repeat the search until all items are found

    I have a spreadsheet that has formulas in Column H that determine if certain data is present in column G, and if so, displays the word "TODAY" in the corresponding row in Column H. I want a macro to search Column H for the cells containing the word "TODAY". When it finds the word "TODAY", it freezes the date in the corresponding row in Column G and then searches for the next word "TODAY" in Column H, until all have been found and all dates have been frozen. Column H will have no more than 200 cells (H6:H206) with the potential for the word "TODAY" in a cell. I know how to freeze the dates but I don't know how to search Column H for the next available "TODAY".
    Sheets("SUMMARY").Select
    ActiveSheet.Unprotect  
       Application.Goto REFERENCE:="TOP"
       Cells.Find(What:="TODAY", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
         ActiveCell.Offset(0, -1).Activate
    Thanks for the assistance. Randy
    Last edited by Leith Ross; 01-06-2014 at 01:30 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search within a column and repeat the search until all items are found

    Not sure about what you mean by freeze. But maybe?

    Sub RandyLiposki()
    Dim rcell As Range
    For Each rcell In Range("H2:H" & ActiveSheet.UsedRange.Rows.Count + 1)
        If rcell.Value Like "*TODAY*" Then
            rcell.Offset(, -1).Value = rcell.Offset(, -1).Value
        End If
    Next rcell
    End Sub

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

    Re: Search within a column and repeat the search until all items are found

    Hello Randy,

    You will need to add your freeze date code to this macro. It is marked by a comment in the Do loop. I am assuming that "Top" is named cell on the worksheet "Summary". If it is not then the code will fail.
    Sub FindAll()
    
        Dim FirstAddx As String
        Dim FoundIt As Range
        Dim Rng As Range
        Dim RngEnd As Range
        Dim Wks As Worksheet
        
            
            Set Wks = Sheets("SUMMARY")
            Wks.Unprotect
            
                Set Rng = Wks.Range("TOP")
                Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
                If RngEnd.Row < Rng.Row Then Exit Sub
                
                Set Rng = Wks.Rnage(Rng, RngEnd)
                
                Set FoundIt = Rng.Find("Today", , xlValue, xlPart, xlByRows, xlNext, False, False, False)
                
                If FouundIt Is Nothing Then Exit Sub
                
                    FirstAddx = FoundIt.Address
                    
                    Do
                        '  --->  Add freeze date code here  <---
                        Set FoundIt = Rng.FindNext(FoundIt)
                        If FoundIt Is Nothing Then Exit Sub
                    Loop Until FoundIt.Address = FirstAddx
                    
    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!)

  4. #4
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Search within a column and repeat the search until all items are found

    Thanks much for your responses. Neither macro was able to find the word "TODAY". Perhaps I misinterpreted what I was supposed to do but I copied them essential verbatim.

    I attempted to attach an image of the spreadsheet so you could see exactly what I am talking about but it doesn't look like it worked.

    The macro simply needs to go from 1 cell to another in column H looking for the word "TODAY". If you can get me that far, I can take it the rest of the way.

    TODAY.JPG

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search within a column and repeat the search until all items are found

    Both codes should do that. If they are not working can you provide a sample with some data as depicted in the .jpg file?

    Sub RandyLiposki()
    Dim rcell As Range
    For Each rcell In Range("H2:H" & ActiveSheet.UsedRange.Rows.Count + 1)
        If rcell.Value = "TODAY" Then
            rcell.Offset(, -1).Value = rcell.Offset(, -1).Value
        End If
    Next rcell
    End Sub

  6. #6
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Search within a column and repeat the search until all items are found

    Still did not work. Here is a sample of the forumulas used in those columns

    TODAY1.JPG

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search within a column and repeat the search until all items are found

    I meant attaching a sample worksheet with some data which is not responding to the macros. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  8. #8
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Search within a column and repeat the search until all items are found

    PS: There is a Loop statement that I inadvertently left out

  9. #9
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Post Re: Search within a column and repeat the search until all items are found

    Sorry for the delay. I have attached a copy of the file that I am using with the macro

    SUMMARY2.xlsm

    Here is a copy of the macro I am attempting to use. Again, the intent of the macro is to freeze the dates in Column G.

    Do
        Cells.Find(What:="TODAY", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        ActiveCell.Offset(0, -1).Activate
        'Freezing of date will occur here
        ActiveCell.Offset(0, 1).Activate
        Selection.ClearContents
        
      If Selection.Value = "" Then Exit Do
        
    Loop

  10. #10
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Search within a column and repeat the search until all items are found



    For those that are interested, I finally got this macro to work. This is a handy little macro and may be beneficial to those that search for specific words in a column or row.

    Do
          
        Cells.Find(What:="TODAY", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        ActiveCell.Offset(0, -1).Activate
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 1).Activate
        Selection.ClearContents
        On Error GoTo ErrorHandler:
    
      Loop
    'ERRORHANDLER NEEDED TO PREVENT ERROR MESSAGE DURING SEARCH FOR "TODAY"
    ErrorHandler:
    Range("H2000").Select
    ActiveCell.FormulaR1C1 = "TODAY" 'PLACES ANOTHER TODAY AT CELL H2000 TO PREVENT ERROR DURING MULTIPLE SAVES ON SAME DAY
    Range("A6").Select
          ActiveSheet.Protect

  11. #11
    Registered User
    Join Date
    11-06-2013
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Search within a column and repeat the search until all items are found

    Thanks much for all of your effort. I have managed to get the find function working with a Do Loop. It moves sucessfully from "Today" to "Today" but when it gets to the last "Today" the macro freezes and won't fully complete the macro. I don't have the ability to attach the spreadsheet.

    Here's my current macro

    Sub FREEZEDATE()
    '
    ' FREEZES DATES ON SUMMARY PAGE'
    
    '
    Sheets("SUMMARY").Select
    ActiveSheet.Unprotect
    Application.ScreenUpdating = False
    Application.Goto Reference:="TOP"
    
    Do
       
       Cells.Find(What:="TODAY", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        ActiveCell.Offset(0, -1).Activate
        'Freezing of date will occur here
        ActiveCell.Offset(0, 1).Activate
        Selection.ClearContents
        ActiveCell.Activate
        If Not Selection.Value = "" Then Exit Do
         
          Range("A6").Select
          ActiveSheet.Protect
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 09-13-2013, 11:02 AM
  2. [SOLVED] Search for a value and if the value is found copy the whole row. And repeat the proces
    By beamonemo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2012, 02:34 PM
  3. [SOLVED] Search for string across header row, then search for another string down found column
    By TucsonJack in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:09 PM
  4. [SOLVED] Macro ignores search code when 1 of the 2 search parameters is not found
    By BrodyNoochie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2012, 05:21 PM
  5. Create a search box that jumps to items found in list
    By cadmancan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-27-2009, 11:44 AM

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