+ Reply to Thread
Results 1 to 3 of 3

Macro needed: list results based on criteria

Hybrid View

nantoy Macro needed: list results... 02-27-2012, 12:33 PM
tigeravatar Re: Macro needed: list... 02-27-2012, 02:03 PM
nantoy Re: Macro needed: list... 02-27-2012, 09:18 PM
  1. #1
    Registered User
    Join Date
    02-27-2012
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro needed: list results based on criteria

    Hi,

    I have a list of companies with the countries they have branches. On a separate sheet is a list of holidays per country.

    I need your help in coding a macro that will create a list of all the holidays available for each company. Attached is a workbook as reference with an expected results tab.

    Would appreciate any help. ThanksCompany Holidays.xls
    Last edited by nantoy; 02-27-2012 at 09:17 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Macro needed: list results based on criteria

    nantoy,

    Welcome to the forum!
    Give this a try:
    Sub tgr()
        
        Dim arrList() As Variant
        Dim arrData() As Variant
        ReDim arrData(1 To 3, 1 To Rows.Count)
        Dim ListIndex As Long
        Dim DataIndex As Long
        Dim rngFound As Range
        Dim strFirst As String
        Dim wsCompany As Worksheet
        Dim wsHoliday As Worksheet
        
        Set wsCompany = Sheets("Company List")
        Set wsHoliday = Sheets("Holiday List")
        
        arrList = wsCompany.Range("A2", wsCompany.Cells(Rows.Count, "B").End(xlUp)).Value
        
        For ListIndex = LBound(arrList, 1) To UBound(arrList, 1)
            Set rngFound = wsHoliday.Columns("A").Find(arrList(ListIndex, 2), , , xlWhole)
            If Not rngFound Is Nothing Then
                strFirst = rngFound.Address
                Do While Not rngFound Is Nothing
                    DataIndex = DataIndex + 1
                    arrData(1, DataIndex) = arrList(ListIndex, 1)
                    arrData(2, DataIndex) = arrList(ListIndex, 2)
                    arrData(3, DataIndex) = rngFound.Offset(, 1).Value2
                    Set rngFound = wsHoliday.Columns("A").Find(arrList(ListIndex, 2), rngFound, , xlWhole)
                    If rngFound.Address = strFirst Then Exit Do
                Loop
                Set rngFound = Nothing
            End If
        Next ListIndex
        
        If DataIndex > 0 Then
            ReDim Preserve arrData(1 To 3, 1 To DataIndex)
            With Sheets.Add(After:=Sheets(Sheets.Count))
                .Name = "Company Holiday Results"
                With .Range("A1:C1")
                    .Value = Array("COMPANY", "DOMICILE", "DATE")
                    .Font.Bold = True
                    .Borders(xlEdgeBottom).LineStyle = xlContinuous
                End With
                .Range("A2:C2").Resize(DataIndex).Value = Application.Transpose(arrData)
                Intersect(.UsedRange, .Columns("C")).NumberFormat = "d-mmm-yy"
                .UsedRange.EntireColumn.AutoFit
            End With
        End If
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    02-27-2012
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro needed: list results based on criteria

    Thanks tigeravatar! Works like a charm :D

+ Reply to Thread

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.6.0 RC 1