|
-
Jul 4th, 2006, 11:02 AM
#1
Thread Starter
Addicted Member
Updating records
Please have a look at http://www.asgsoft.net/form.xls
You will see that there is a sheet for records
and also there is an input sheet. What i want is to be able to see that if the information entered has broken the record. However there are two types of measurements. There is time, so the smaller the better but there are also distance events so the longer that better.
Do you think you can help me?
Thank you
-
Jul 4th, 2006, 03:18 PM
#2
Frenzied Member
Re: Updating records
With your current setup, it looks like you'll have to get every entry for a particular event first, in order to check time/distance in any case. But to check whether you want shortest or longest, you'll have to check at least the first letter of each event. If it's numeric - IsNumeric(Left(somecell, 1)) - then check time. Otherwise, check distance.
If this was Access I'd set it up differently, but I know Access lots better than Excel.
Of course, this won't work if you have a time event that begins with a letter, or a distance event that begins with a number, but I didn't see any in your example.
Another option would be to either separate time/distance into 2 columns, or add a column with some type of identifying code - T and D, for instance.
Tengo mas preguntas que contestas
-
Jul 4th, 2006, 03:57 PM
#3
Thread Starter
Addicted Member
Re: Updating records
I was thinking of using an IF statement that checks what event it is? and then I have two functions to check if a record is broken. One for lengths and the other for time. But what I have trouble with is to check that a record was broken.
-
Jul 4th, 2006, 06:54 PM
#4
Frenzied Member
Re: Updating records
Sorry, don't know how to do that between sheets. Access yes, Excel no.
Tengo mas preguntas que contestas
-
Jul 5th, 2006, 03:03 PM
#5
Re: Updating records
You could perform a Sort based on user/time/ascending and then get the first record for that user and look at the cell value. Then do the same for distance with th eappropriate changes.
In your calling code you will perform the first sort and check the value then again another call to sort with the next criteria and get its value. Then if the record is broken by one r oth then you can inform the user or ? Just reference the other sheet.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 5th, 2006, 04:04 PM
#6
Thread Starter
Addicted Member
Re: Updating records
But is there no way to check if the record is broken as it's being entered?
-
Jul 5th, 2006, 04:50 PM
#7
Re: Updating records
yes if can be done, you would have to loop through all rows to compare the the result for each race type, as this entails searchin the whole sheet for each race type it might be better to put each race type into a named range, then you can just work with all rows within that named range
pete
-
Jul 5th, 2006, 05:06 PM
#8
Re: Updating records
You could list the records of whatever type is being entered on the form itself. Or even use a UserForm instead of a Sheet for record entry.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 6th, 2006, 01:01 PM
#9
Thread Starter
Addicted Member
Re: Updating records
 Originally Posted by westconn1
yes if can be done, you would have to loop through all rows to compare the the result for each race type, as this entails searchin the whole sheet for each race type it might be better to put each race type into a named range, then you can just work with all rows within that named range
pete
can you please give me some code examples?
Last edited by asgsoft; Jul 6th, 2006 at 01:05 PM.
-
Jul 7th, 2006, 05:12 AM
#10
Re: Updating records
VB Code:
Sub checkrecord()
Dim s As Sheet4, f As Sheet1
Set s = Sheet4
Set f = Sheet1
n = f.Name
's.Activate
For i = 2 To s.UsedRange.Rows.Count
If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
If f.Cells(8, 2) > s.Cells(i, 6) Then 'compare time/distance, not sure if high or low is better
s.Cells(i, 2) = f.Cells(2, 2) ' update record if better
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
End If
Exit For
End If
Next
'for i = 1 to
End Sub
try this see if it works right, check if i have the compare of time/distance round the right way, probably not, the code will just overwrite the new details into the rcords sheet
pete
-
Jul 7th, 2006, 02:59 PM
#11
Thread Starter
Addicted Member
Re: Updating records
I don't have a Sheet4 or Sheet1
Also how would you say I can check if the distance is more or time is less?
-
Jul 8th, 2006, 02:23 AM
#12
Re: Updating records
you do have those sheets, cos i was working in your spreadsheet.
sheet4 is the same as sheets(4) or sheets("records")
which is faster, smaller time/distance or bigger??
the code i posted checked if time distance was greater, then updated the record, if time/distance should be shorter to break record then change the greater than to less than.
as it is for a particular event (eg. 100m) why not just record the time instead of time/distance?
pete
-
Jul 9th, 2006, 10:12 AM
#13
Thread Starter
Addicted Member
Re: Updating records
OK its working, however, the time distance is a bit confusing. If it's a timed event such as 100m,200m,300m,400m,800m,1500m and relay then the shorter the time the better. Otherwise if its a distance event such as Shot,Discus,Javelin,High Jump,Long Jump,Triple Jump then the longer the distance the better.
All the times are in seconds and distances are in centimeters so its easier to compare.
How can I do this?
When I try this I get an error:
VB Code:
Sub checkrecord2()
Dim s As Sheet4, f As Sheet1
Set s = Sheet4
Set f = Sheet1
n = f.Name
For i = 2 To s.UsedRange.Rows.Count
event1 = f.Cells(6, 2)
If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
If event1 = "100m" Or event1 = "200m" Or event1 = "300m" Or event1 = "400m" Or event1 = "800m" Or event1 = "1500m" Or event1 = "Relay" Then
If f.Cells(8, 2) < s.Cells(i, 6) Then
s.Cells(i, 2) = f.Cells(2, 2)
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
MsgBox "Record Broken!", vbInformation, "Record Broken"
Else
If f.Cells(8, 2) > s.Cells(i, 6) Then
s.Cells(i, 2) = f.Cells(2, 2)
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
MsgBox "Record Broken!", vbInformation, "Record Broken"
End If
End If
End If
Exit For
End If
Next
End Sub
Last edited by asgsoft; Jul 9th, 2006 at 12:51 PM.
-
Jul 9th, 2006, 09:28 PM
#14
Re: Updating records
what error, where?
try using select case or your events, it will probably be much easier to do that way
pete
-
Jul 10th, 2006, 01:11 AM
#15
Thread Starter
Addicted Member
Re: Updating records
I changed it a bit and I am not able to see if the sport is a distance one. I am not getting any errors but it won't just recognise them. Have a look at this please:
VB Code:
Sub checkrecord2()
Dim s As Sheet4, f As Sheet1
Set s = Sheet4
Set f = Sheet1
n = f.Name
's.Activate
For i = 2 To s.UsedRange.Rows.Count
event1 = f.Cells(6, 2)
If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
If event1 = "100m" Or event1 = "200m" Or event1 = "300m" Or event1 = "400m" Or event1 = "800m" Or event1 = "1500m" Or event1 = "Relay" Then
If f.Cells(8, 2) < s.Cells(i, 6) Then
s.Cells(i, 2) = f.Cells(2, 2) ' update record if better
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
MsgBox "Record Broken!", vbInformation, "Record Broken"
End If
If event1 = "Shot Putt" Or event1 = "Discus" Or event1 = "Javelin" Or event1 = "High Jump" Or event1 = "Long Jump" Or event1 = "Triple Jump" Then
If f.Cells(8, 2) > s.Cells(i, 6) Then
s.Cells(i, 2) = f.Cells(2, 2) ' update record if better
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
MsgBox "Record Broken!", vbInformation, "Record Broken"
End If
End If
End If
Exit For
End If
Next
'for i = 1 to
End Sub
-
Jul 10th, 2006, 03:23 AM
#16
Re: Updating records
VB Code:
Sub checkrecord()
Dim s As Sheet4, f As Sheet1, newrecord As Boolean
Set s = Sheet4
Set f = Sheet1
n = f.Name
's.Activate
For i = 2 To s.UsedRange.Rows.Count
If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
a = f.Cells(6, 2)
Select Case f.Cells(6, 2)
Case "100m", "200m", "400m", "800m", "1500m", "Relay"
If f.Cells(8, 2) < s.Cells(i, 6) Then newrecord = True
Case "Shot Putt", "Long Jump", "Triple Jump", "High Jump", "Discus", "Javelin"
If f.Cells(8, 2) > s.Cells(i, 6) Then newrecord = True
Case Else
MsgBox "This event not in record list"
End Select
If newrecord Then 'compare time/distance, not sure if high or low is better
s.Cells(i, 2) = f.Cells(2, 2) ' update record if better
s.Cells(i, 6) = f.Cells(8, 2)
s.Cells(i, 7) = Year(Now)
End If
Exit For
End If
Next
'for i = 1 to
End Sub
try this
pete
-
Jul 10th, 2006, 11:43 AM
#17
Thread Starter
Addicted Member
Re: Updating records
it works
you are a genious
-
Jul 11th, 2006, 02:59 AM
#18
Re: Updating records
Case Else
MsgBox "This event not in record list"
this will never do anything, because if the event does not match one of the events already in the record list it will never get that far, i think this is the case with "Shot" or one event that is different in your drop down box to what is in the records, also if you start a new event there is no provision to add that to the records, it will only update existing records
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|