+ Reply to Thread
Results 1 to 5 of 5

Searching & Displaying data

Hybrid View

  1. #1
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Searchin & Displaying data

    How about this
    Option Explicit
    Sub MakeReport()
    
    Dim WsData As Worksheet, WsReport As Worksheet
    Dim NameRng As Range, CurName As Range
    Dim JobRng As Range, JobItem As Range
    Dim LastRow As Long 'Multiple use
    Dim ReportRowCounter As Long
    Dim JobRolesStr As String, DescriptionStr As String
    Dim FullNameStr As String, CurFullNameStr As String
    
    Set WsData = Sheets("Data")
    Set WsReport = Sheets("Report")
    
    'Set all ranges
    LastRow = WsData.Cells(WsData.Cells.Rows.Count, "A").End(xlUp).Row
    Set NameRng = WsData.Range("A3:A" & LastRow + 1)
    LastRow = WsData.Cells(WsData.Cells.Rows.Count, "F").End(xlUp).Row
    Set JobRng = WsData.Range("F3:F" & LastRow)
    
    'Clean report
    WsReport.Range("A3", WsReport.Cells.SpecialCells(xlCellTypeLastCell)).ClearContents
    
    ReportRowCounter = 3 'Start at row 3.
    FullNameStr = ""
    For Each CurName In NameRng
      CurFullNameStr = Trim(CurName) & " " & Trim(CurName.Offset(0, 1))
      If CurFullNameStr <> FullNameStr Then 'Unequal to previous
        If FullNameStr <> "" Then
          WsReport.Cells(ReportRowCounter, "A") = FullNameStr
          WsReport.Cells(ReportRowCounter, "B") = Right(JobRolesStr, Len(JobRolesStr) - 3)
          WsReport.Cells(ReportRowCounter, "C") = Right(DescriptionStr, Len(DescriptionStr) - 3)
          ReportRowCounter = ReportRowCounter + 1
        End If
        
        FullNameStr = CurFullNameStr
        JobRolesStr = ""
        DescriptionStr = ""
      End If
      
      JobRolesStr = JobRolesStr & ", " & Chr(10) & CurName.Offset(0, 3)
      
      For Each JobItem In JobRng
        If JobItem = CurName.Offset(0, 3) Then DescriptionStr = DescriptionStr & ", " & Chr(10) & JobItem.Offset(0, 2)
      Next
    Next
    End Sub
    Note that your Namestring are not the same and they contain spaces.
    Attached Files Attached Files
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  2. #2
    Forum Contributor
    Join Date
    01-26-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    162

    Re: Searchin & Displaying data

    Hello, thank you very much you are an expert pro. It is bringing up most of the data but comes up with error message: Run-time error '5' Invalid procedures call or argument. (vbs code line ( WsReport.Cells(ReportRowCounter, "C") = Right(DescriptionStr, Len(DescriptionStr) - 3) I dunno if there is something wrong in this maybe??


    Many many many thanks just for spending your time to help.
    Respect and It is much appreciated

+ 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