+ Reply to Thread
Results 1 to 4 of 4

Modify Macro to search columns before rows

Hybrid View

m3k1rk Modify Macro to search... 09-13-2013, 08:03 AM
patel45 Re: Modify Macro to search... 09-13-2013, 08:46 AM
watersev Re: Modify Macro to search... 09-13-2013, 09:09 AM
m3k1rk Re: Modify Macro to search... 09-16-2013, 11:51 AM
  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Modify Macro to search columns before rows

    Good Afternoon

    I have a macro in the attached spread sheet which is fab and works like a dream, I just need it to search columns before rows (default I guess). It may be that somebody has booked an appointment at 11am on Tuesday and also at 4pm on Monday (see Client X in the sheet. At the moment the returning list would put Tuesday before Friday but I'd like it the other way around.

    Sadly I can't just sort the list by date as often the returned text is not formatted as a date.

    Many thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Modify Macro to search columns before rows

    apply these changes
         Set rngFound = ws.Cells.Find(strFind, , xlValues, xlWhole, xlByColumns)
     ...............
        arrResults(ResultIndex, 1) = .EntireColumn.Find("*", .EntireColumn.Cells(.EntireColumn.Cells.Count), , , xlByRows).Text
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Modify Macro to search columns before rows

    hi m3k1rk, to address both issues:

    Option Explicit
    
    Sub btnSearch_Click()
        
        Dim ws As Worksheet
        Dim rngFound As Range
        Dim arrResults() As Variant
        Dim ResultIndex As Long
        Dim lInterval As Long
        Dim lNumCols As Long
        Dim strFirst As String
        Dim strFind As String
    
        strFind = Range("C3").Text
        If Len(strFind) = 0 Then
            Range("C3").Select
            MsgBox "Must provide a name to search for"
            Exit Sub
        End If
        
        lInterval = 5000
        lNumCols = 3
        ReDim arrResults(1 To lInterval, 1 To lNumCols)
        Range("C6:C" & Rows.Count).Resize(, lNumCols).ClearContents
        
        For Each ws In ActiveWorkbook.Sheets
            If ws.Name <> ActiveSheet.Name Then
                Set rngFound = ws.Cells.Find(strFind, , xlValues, xlWhole, xlColumns)
                If Not rngFound Is Nothing Then
                    strFirst = rngFound.Address
                    Do
                        If ResultIndex = lInterval Then
                            Cells(Rows.Count, "C").End(xlUp).Offset(1).Resize(ResultIndex, lNumCols).Value = arrResults
                            ReDim arrResults(1 To lInterval, 1 To lNumCols)
                            ResultIndex = 0
                        End If
                        ResultIndex = ResultIndex + 1
                        With rngFound.CurrentRegion
                            arrResults(ResultIndex, 1) = Intersect(rngFound.CurrentRegion.EntireColumn, ws.UsedRange.Resize(1)).Cells(1, 2)
                            arrResults(ResultIndex, 2) = Intersect(.Columns(1), ws.Rows(rngFound.Row)).Text
                            arrResults(ResultIndex, 3) = .Cells(1, 2).Text
                        End With
                        Set rngFound = ws.Cells.Find(strFind, rngFound, xlValues, xlWhole)
                    Loop While rngFound.Address <> strFirst
                End If
            End If
        Next ws
        
        If ResultIndex > 0 Then
           With Cells(Rows.Count, "C").End(xlUp).Offset(1).Resize(ResultIndex, lNumCols)
                .Resize(, 1).NumberFormat = "m/d/yyyy"
                .Resize(, 1).Offset(, 1).NumberFormat = "#,##0.00_);[Red](#,##0.00)"
                .Value = arrResults
            End With
        End If
    
    End Sub
    Last edited by watersev; 09-13-2013 at 09:19 AM.

  4. #4
    Registered User
    Join Date
    08-16-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Modify Macro to search columns before rows

    Thank you both, I will give these a go

+ 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. Complecate Macro to search value of intersect Rows and Columns with conditions
    By hassan khansa in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-26-2013, 11:00 AM
  2. Macro help to search in all columns and delete rows accordingly
    By JonnyNYC90 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-20-2012, 03:44 PM
  3. Modify Macro Search & Replace Formatting for part of cell
    By tkeiffer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2011, 05:48 PM
  4. Search by more than 2 criteria (help in macro modify)
    By Wiecman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2010, 05:44 AM
  5. Replies: 5
    Last Post: 08-16-2006, 02:05 PM

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