+ Reply to Thread
Results 1 to 5 of 5

Searching & Displaying data

Hybrid View

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

    Searching & Displaying data

    Hello there,

    I have got two worksheets. One that has got the data and one that displays the reports.

    A,B,C,D is data one (I am only going to need A,B & D)
    F,G,H is data two.

    First of all I would like to join B&A in report sheet with a space so I will have Name Surname.

    Then I would like to bring up all values from column D that matching to B&A(if Surname Name is repetitive just bring it as one) name
    but as one and bring it to the report sheet in column B.

    After that I would like all the values of D that has been matched and displayed in column B (report sheet) with the name from B,A to check if they match with column F and if they do bring the values of column H in report sheet in column C.

    Finally in report sheet create an interactive button(or something) with the name Start Report and once that pressed run the macro.

    I have attached a sample of the spreadsheet where it has been explained thorough and in report sheet I have type how it would look. (the data i quite big containing approx 30.000 records (a,b,c,d) and approx 2000 records (F,G,H).

    Many thanks and I hope I have come to the right section this time.


    Kind Regards
    Last edited by greekboyuk; 03-10-2010 at 03:48 AM.

  2. #2
    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

  3. #3
    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

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

    Re: Searching & Displaying data

    The only think I can think of is when the DescriptionStr Length is 0 and 0-3=-3, that would result in an error.

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

    Re: Searching & Displaying data

    hi thank you for quick response. The problem is solved. it was showin the error as the one of the job roles wasn't in the list. It is working lovely, thank u so much. The only thing that I would like to ask is is it possible in the description cell where my report is to have the results displayed next to each other by a comma instead of underneath each other? the cell high can go only up to 409pixel so it is very hard to see all my data.
    Also in the description I can see exactly the same description. is it any chance to delete similar descriptions?

    Many many thanks and u have done a great job.

    I will mark it as solve and if u like to help that gonna be great

+ 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