selecting data from a database

I'll try my best to explain what  i I want to do....

I have a databse that contains a list of times recorded by athletes over 
various distances.

I would like ot be able to run a macro that compiles a report by selecting 
personal best times by athletes name for the various distances. the database 
is continually added to, athletes times are constantly updated so refencing 
specific cells is not feasible. 

I currently sort the database by name, distance, best time for that distance
so I can see an athletes history but need a method to extract the best times 
for each discipline




-- 
thanks 
Roy
0
Utf
3/26/2010 10:23:01 AM
excel.misc 78881 articles. 5 followers. Follow

3 Replies
662 Views

Similar Articles

[PageSpeed] 46

You could probably use a sumproduct or sum(if array formula for this.

      If desired, send your file to my address below. I will only look if:
      1. You send a copy of this message on an inserted sheet
      2. You give me the newsgroup and the subject line
      3. You send a clear explanation of what you want
      4. You send before/after examples and expected results.

-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Roy Gudgeon" <RoyGudgeon@discussions.microsoft.com> wrote in message 
news:66AADB94-09A5-4903-8C38-52E80371CD64@microsoft.com...
> I'll try my best to explain what  i I want to do....
>
> I have a databse that contains a list of times recorded by athletes over
> various distances.
>
> I would like ot be able to run a macro that compiles a report by selecting
> personal best times by athletes name for the various distances. the 
> database
> is continually added to, athletes times are constantly updated so 
> refencing
> specific cells is not feasible.
>
> I currently sort the database by name, distance, best time for that 
> distance
> so I can see an athletes history but need a method to extract the best 
> times
> for each discipline
>
>
>
>
> -- 
> thanks
> Roy 

0
Don
3/26/2010 12:13:30 PM
This looks like a perfect application for a Pivot Table. Here's a primer on 
them: http://www.cpearson.com/excel/pivots.htm

Regards,
Fred

"Roy Gudgeon" <RoyGudgeon@discussions.microsoft.com> wrote in message 
news:66AADB94-09A5-4903-8C38-52E80371CD64@microsoft.com...
> I'll try my best to explain what  i I want to do....
>
> I have a databse that contains a list of times recorded by athletes over
> various distances.
>
> I would like ot be able to run a macro that compiles a report by selecting
> personal best times by athletes name for the various distances. the 
> database
> is continually added to, athletes times are constantly updated so 
> refencing
> specific cells is not feasible.
>
> I currently sort the database by name, distance, best time for that 
> distance
> so I can see an athletes history but need a method to extract the best 
> times
> for each discipline
>
>
>
>
> -- 
> thanks
> Roy 

0
Fred
3/26/2010 1:27:32 PM
I agree that it's probably something that a Pivot Table will probably deal 
with well (although I haven't tried setting one up for your situation).
But since you asked for a macro, here you go (and it may give you some 
appreciation for the work that a Pivot Table does at times <grin>):

Sub ReportPersonalBests()
  'change these constants
  'to tailor to your
  'workbook and worksheets
  'sheet with all entries on it
  Const dbSheetName = "Sheet1"
  'column with names in it
  Const nameCol = "A"
  'column with events listed
  Const eventCol = "B"
  'column with times in it
  Const timeCol = "C"
  'name of sheet to place
  'results onto
  Const pbSheetName = "Sheet2"
  'end of user definable values
  '
  Dim lastRow As Long
  Dim theAthletes() As String
  Dim theEvents() As String
  Dim ALC As Integer ' loop counter
  Dim ELC As Integer ' loop counter
  Dim pbTime As Variant
  Dim dbSheet As Worksheet
  Dim pbSheet As Worksheet
  Dim namesList As Range
  Dim anyName As Range
  Dim foundFlag As Boolean
  
  'assumes database sheet has
  'labels in row 1
  Set dbSheet = ThisWorkbook.Worksheets(dbSheetName)
  lastRow = dbSheet.Range(nameCol & Rows.Count). _
   End(xlUp).Row
  If lastRow < 2 Then
    'no entries in name column
    MsgBox "No data to process, quitting"
    Set dbSheet = Nothing
    Exit Sub
  End If
  Set namesList = _
   dbSheet.Range(nameCol & "2:" & _
    nameCol & lastRow)
  'set up the personal best report
  'sheet to receive the results
  'clear any previous report
  Set pbSheet = ThisWorkbook.Worksheets(pbSheetName)
  pbSheet.Cells.Clear
  pbSheet.Range("A1") = "Athlete"
  pbSheet.Range("B1") = "Event"
  pbSheet.Range("C1") = "Best Time"
  'get list of unique names
  'save in array theAthletes()
  ReDim theAthletes(1 To 1)
  For Each anyName In namesList
    foundFlag = False
    For ALC = LBound(theAthletes) To UBound(theAthletes)
      If anyName = theAthletes(ALC) Then
        foundFlag = True
        Exit For
      End If
    Next ' end theAthletes loop
    If Not foundFlag Then
      'add name to the list
      theAthletes(UBound(theAthletes)) = anyName
      ReDim Preserve _
       theAthletes(1 To UBound(theAthletes) + 1)
    End If
  Next ' end anyName loop
  'remove the empty array element
  If UBound(theAthletes) > 1 Then
    ReDim Preserve _
     theAthletes(1 To UBound(theAthletes) - 1)
  End If
  'now we have a list of the individual athletes
  'we have to go through it one at a time and
  'find what events they participated in
  'after doing that, we then have to go back
  'and find each entry for the athlete:event
  'and pick up the minimum time for them
  'to report.
  For ALC = LBound(theAthletes) To UBound(theAthletes)
    'build list of events they participated in
    ReDim theEvents(1 To 1)
    For Each anyName In namesList
      If anyName = theAthletes(ALC) Then
        foundFlag = False
        For ELC = LBound(theEvents) To UBound(theEvents)
          If dbSheet.Range(eventCol & anyName.Row) = _
           theEvents(ELC) Then
            'already in list
            foundFlag = True
            Exit For
          End If
        Next ' end ELC loop
        If Not foundFlag Then
          'add event to list
          theEvents(UBound(theEvents)) = _
           dbSheet.Range(eventCol & anyName.Row)
          ReDim Preserve _
           theEvents(1 To UBound(theEvents) + 1)
        End If
      End If
    Next ' end anyName loop
    If UBound(theEvents) > 1 Then
      ReDim Preserve _
       theEvents(1 To UBound(theEvents) - 1)
    End If
    'ready to match name:event to pick up best times
    'set pbTime to very large value of 100
    'this time is presumed to be hours, but in any
    'case it must be larger than any possible
    'actual reported time entry
    For ELC = LBound(theEvents) To UBound(theEvents)
      'ready to match name:event to pick up best times
      'set pbTime to very large value of 100
      'this time is presumed to be hours, but in any
      'case it must be larger than any possible
      'actual reported time entry
      pbTime = 1000
      For Each anyName In namesList
        If anyName = theAthletes(ALC) And _
         dbSheet.Range(eventCol & anyName.Row) = _
         theEvents(ELC) Then
         'name and event match, see if it's a
         'new personal best time
          If dbSheet.Range(timeCol & anyName.Row) < pbTime Then
            pbTime = dbSheet.Range(timeCol & anyName.Row)
          End If
        End If
      Next ' end anyName loop
      lastRow = pbSheet.Range("A" & Rows.Count).End(xlUp).Row + 1
      pbSheet.Range("A" & lastRow) = theAthletes(ALC)
      pbSheet.Range("B" & lastRow) = theEvents(ELC)
      pbSheet.Range("C" & lastRow) = pbTime
    Next ' end ELC loop
  Next ' end of ALC loop
  'all done, do housekeeping and inform user
  Set namesList = Nothing
  Set pbSheet = Nothing
  Set dbSheet = Nothing
  MsgBox "Personal Best List Compilation Completed"
End Sub




"Roy Gudgeon" wrote:

> I'll try my best to explain what  i I want to do....
> 
> I have a databse that contains a list of times recorded by athletes over 
> various distances.
> 
> I would like ot be able to run a macro that compiles a report by selecting 
> personal best times by athletes name for the various distances. the database 
> is continually added to, athletes times are constantly updated so refencing 
> specific cells is not feasible. 
> 
> I currently sort the database by name, distance, best time for that distance
> so I can see an athletes history but need a method to extract the best times 
> for each discipline
> 
> 
> 
> 
> -- 
> thanks 
> Roy
0
Utf
3/26/2010 2:24:01 PM
Reply:

Similar Artilces:

sort alphanumeric data
I have data with mix number of digits and I like to sort them. Somehow, the normal sorting process give me a not so desired result. Can anyone help? A10 B100 A2 AA1 AD200 A1 The result I am looking for is: A1 A2 A10 B2 B100 AD200 I think your example wasn't exactly right' look at the B2 and AA1 entries. But I assume you want to sort like the Excel row and column identifiers; I also assume there will be two alpha characters at most Go to the VB Editor (ALT+F11) Insert>Module Paste these two functions in the code window: Function PartOne(a As String) As String Dim i As Long For ...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

move row data to columns
We had a problem with some test data and instead of test results being recorded in multiple rows 5 columns wide, all of the data was recorded in one row multiple columns wide. The data consists of 5 readings taken every second for a period of 2 hours. Each reading is in it's own cell (no cell contains more than one reading). Do you know of a way that I can move each set of readings (5 test results) into it's own 5 column wide row? i.e. currently shows in single row as: 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 234, 234, 234, 234, 234, etc. and I need in 5 column wide rows: 0, 0, 0, ...

Pivot Table Data
This is a multipart message in MIME format. --=_alternative 006B899F86256E2F_= Content-Type: text/plain; charset="us-ascii" I have a file that contains pivot tables along with some buttons and macros to change the way the pivot table looks depending on what type of information that you would like to view. The pivot table is based on data on a separate worksheet but is within the same workbook (separate tabs). If I change my data source (i.e. I change the names of individuals to new names) and refresh my pivot table, the information changes like I want it to. However, if I de...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

UK Fantasy Football Player Data?
Hi, Does anyone know where I can get hold of excel spreadsheets with player data for the forth coming UK Fantasy Football season? -- Rich http://www.ukfantasyfootball.info ...

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Data Type Problem
Hi Experts In VC++, the maximum range for data type is 10 bytes which is the range for long double __int64 has 8 bytes range. Is there any data type which has range more than 10 bytes? Is there any data type which has range 16 bytes If not supported, then can i create my own data type which range should be more than 10 bytes? if yes then please reply thanks If you need to play with huge sections of numbers, you can always use a unsigned char array, and use bit shifting backwards and forwards for calculation (complex). Otherwise, for numbers there are other string ba...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

NTFS file meta data
This is a multi-part message in MIME format. ------=_NextPart_000_008A_01CAFF1D.F88487D0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit How can I set the From, Subject, To properties of Outlook MSG files to display in a manner as EML files? I have folders of thousands of these files and would love to create a batch processors to do this. TIA Russ ------=_NextPart_000_008A_01CAFF1D.F88487D0 Content-Type: image/png; name="Capture.PNG" Content-Transfer-Encoding: base64 Conte...

Data from multiple sheets and workbooks
Each week I receive a workbook from one of my customers. It contains mutliple sheets with salesnumbers from all the branch of my customer. Each sheet contains from 1 000 to 15 000 lines of salesdata. Every article sold gets one line in the sheets. Each workbook are named "weeknr.xls" and are stored in the same folder. Now my question/problem. I need to gather all sales info for one branch on one article from all the weeks. I know how to get the data from one workbook to another, but how do I get it to scan all the workbooks in the folder. Any ideas. Dim oFSO Sub LoopFolder...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

Graphing only some of the data?
I have a spreadsheet with groups of repeating rows and cells that look something like this 1AA 1AB 1A 1BA 2BB 2B 1CA 1CB 1C 2AA 2AB 2A 2BA 2BB 2B 2CA 2CB 2C The rows/cells beginning with "1" make up one batch of data. The rows/cells beginning with "2" make up another. I add a new batch every week. I want to create a graph that captures only 1CC, 2CC, 3CC, 4CC, etc. There are always the same numbers of rows between the cells. I've thought about capturing 1CC, 2CC, 3CC, etc in a list in another area of the spreadsheet and graphing that list, but I don't ...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

Can COMPILE ON DEMAND result database corruption?
Is it a known issue?Vladimir Cvajniga: COMPILE ON DEMAND is ON.David W. Fenton: Turn it OFF and you'll have less corruption.See David W. Fenton's post (March 4 th 2007 14:55) in the thread "Frequent Access 2003 corruption that cannot be repaired". Hello, Tom,MS guys seem that they ignore some recommendations... even from their colleagues. ;-(It's poor programming-language-design if it enables you to omit basics of programming.Luckily, I'm comming from Pascal-programmer-group so that I always declare variables. But to avoid problems I always check this setting in VB &a...

Importing data 02-12-04
Does anyone know if you can import data into the cases? I know you can import into the contacts, but can you import cases? The Data Migration Framework should be able to do this. Gill >-----Original Message----- >Does anyone know if you can import data into the cases? I >know you can import into the contacts, but can you import >cases? >. > ...

Money 2004/05
I have recently purchased a new computer and installed Money onto the new computer (Money version says Copyright 2004, but I think it is 2005 version). I have then simply copied across the data files My Money Backup (Microsoft Money backup File) and my money backup2 (Microsoft Money file) to the new computer...For some reason I just cannot get Money to open the data files on the new computer. When I try to open the Money file, I receive the following message; "Money will convert your file so that you can work with it in Money. First, Money will make a copy of your original file, ...

Can I add Java Data types in Microsoft Visio?
I want to design a UML diagram of a java application. Can i add Java data types in Microsoft Visio 2003? ...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

How can I tell is a posted Invoice is voided via database?
I have 2 invoices in Great Plains. Both were posted, but one was voided after is was posted. In the sales inquiry I see the voided transaction with a * next to the work open telling me it is voided. When I compare the 2 order rows in great plains SELECT TOP 1000 * FROM SOP30200 WHERE (SOPNUMBE = '1115060') OR (SOPNUMBE = '1127570a') I do not see anything different other than the dates an dollar amounts. How am I supposed to know what invoice is voided and what is not? SELECT * FROM SOP30200 WHERE VOIDSTTS = 1 Best regards, -- MG.- Mar...

Custom Data on Receipts
Hi, I'm not sure if this is possible, but does anyone know of a way to display data from a custom table on a receipt? Thanks dave The custom data would need to be set to the Session.Variable(1-10) before PrintReceipt Hook is called. You can use a DLL addon to set your custom data. You need to be careful that no other addon is using the same variables. If the data is static then you can just modify the receipt and hard code the information into the body. Rob "Dave" <Dave@discussions.microsoft.com> wrote in message news:261BCAF0-E737-48CB-B46B-100E00A0AA00@microso...

Data Migration Manager apparently does not have correct Mappings for BCM 2007 Data
I have been trying unsuccessfully for quite some time to migrate BCM 2007 data to CRM 4.0 via the Data Migration Manager using the existing mapping for BCM 2007. However, once I am in there, I have to re-map all data, and even after that, I am unable to successfully import the data. Has anyone had the same issue, and if so, is there a different mapping I should be using? Thanks. what are the failure errors are you getting? are you mapping any data to a lookup field? it is usually a data related issues! -- Kamal Hitari MBSS, MCNPS, MCTS 2B.net Ltd http://kamalhitari.blogspot.com jdmic...

data validation vs combobox
hello there excel gurus.I am largely self taught in excel and can write straightforward macros and have a pretty good grasp of some of the functions.I have always used form comboboxes for my pull down lists.I notice that you seem to prefer the data validation list,pros and cons.?I like that the fom combo box is always there. -- paul remove nospam for email addy! Paul: There's bunches of companies who don't let their users run macros, for one. For another, Data Validation is, IMHO, much easier to show someone how to do. Comboboxes ALWAYS show their dropdown arrow. Comboboxes ar...