Kelly05201
New Member
- Joined
- Jun 17, 2016
- Messages
- 29
Hello all.. learning this vba stuff one google search at a time is tough! I'm knee deep into a project that's well beyond my skill set.. but learning fast. The trouble I'm having is how to reference other cells in proper syntax.. and understanding how to specify a range... can someone get me on the right track?
Workbook for my horse club.
My code so far:
Sheet name: "Registration" (The sub will reside in this sheet module)
*note: Cells A1, B1, C1, D1, and E1 are the only cells in the whole sheet that aren't dynamic. All other cell values change daily.
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]FIRST NAME[/TD]
[TD]LAST NAME[/TD]
[TD]HORSE NAME[/TD]
[TD]......[/TD]
[TD]HORSE TAG #[/TD]
[TD]POLES[/TD]
[TD]BARRELS[/TD]
[TD]FIGURE 8[/TD]
[TD]SPEAR RINGS[/TD]
[TD]BALL AND CHAIN[/TD]
[TD]KEYHOLE[/TD]
[TD]ZIG ZAG[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]SUSIE[/TD]
[TD]SMITH[/TD]
[TD]VIPER[/TD]
[TD][/TD]
[TD]55[/TD]
[TD]Adult[/TD]
[TD]Adult[/TD]
[TD][/TD]
[TD][/TD]
[TD]Adult[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]SALLY[/TD]
[TD]SMITH[/TD]
[TD]SABER[/TD]
[TD][/TD]
[TD]41[/TD]
[TD]Adult[/TD]
[TD]Adult[/TD]
[TD]Adult[/TD]
[TD]Adult[/TD]
[TD][/TD]
[TD][/TD]
[TD]Adult[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]KARMA[/TD]
[TD][/TD]
[TD]29[/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]BILL[/TD]
[TD]BARKER[/TD]
[TD]ACE[/TD]
[TD][/TD]
[TD]22[/TD]
[TD]Jack Benny[/TD]
[TD]Jack Benny[/TD]
[TD]Jack Benny[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]ACE[/TD]
[TD][/TD]
[TD]22[/TD]
[TD]Youth[/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD]Youth[/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD]JOE[/TD]
[TD]JOHNSON[/TD]
[TD]JACKO[/TD]
[TD][/TD]
[TD]88[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Jack Benny[/TD]
[/TR]
</tbody>[/TABLE]
The purpose of the sub() is to check the event sheets for the existence of a proper rider and horse entry... kind of self explanatory, but I'm showing the sheets after the sub runs for clarity...
Sheet name: "Adult POLES" (one of 21 possible division & event sheet names)
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]FIRST NAME[/TD]
[TD]LAST NAME[/TD]
[TD]HORSE NAME[/TD]
[TD]HORSE TAG #[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]SUSIE[/TD]
[TD]SMITH[/TD]
[TD]VIPER[/TD]
[TD]55[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]SALLY[/TD]
[TD]SMITH[/TD]
[TD]SABER[/TD]
[TD]41[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Sheet name: "Youth BALL AND CHAIN" (Another of 21 possible division & event sheet names)
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]FIRST NAME[/TD]
[TD]LAST NAME[/TD]
[TD]HORSE NAME[/TD]
[TD]HORSE TAG #[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]KARMA[/TD]
[TD]29[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]ACE[/TD]
[TD]22[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Many thanks to those who took the time to read, and bigger thanks to anyone who can help get me on track !
Workbook for my horse club.
My code so far:
Code:
Private Sub Worksheet_SelectionChange(ByVal target As Range)
On Error Resume Next
If Not Intersect(target, Range("A2:L70")) Is Nothing Then
Dim SheetTarget As Worksheet
Dim Registration As Worksheet
Dim HorseNumber As Range
Dim cell As Range
Dim EntryVerified As Boolean
Const RegistrationName = "Registration"
Dim LastRow As Long
LastRow = TargetSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For Each cell In Registration.Range("F2:L70") 'test each cell for exisitng matches on TargetSheet
SheetTarget = ""
If IsEmpty(cell) = False Then 'rider has entered that event, cell value indicates division
SheetTarget = cell.Value & " " '& [value of row 1 @ same column]
'CHECK FOR AN EXACT MATCH ON TargetSheet OF ALL: HORSE NUMBER ("D"), FIRST NAME ("A") AND LAST NAME ("B")
'For Each HorseNumber in range(SheetTarget("D2:D70"))
EntryVerified = False
'If HorseNumber = Registration.cell("E" & Row()) And
'HorseNumber("A" & Row()) = cell("A" & Row()) And
'HorseNumber("B" & Row()) = cell("B" & Row()) Then
EntryVerified = True
Exit For
End If
If EntryVerified = False Then
cell.Offset("A" & Row()).Copy (SheetTarget("A" & LastRow)) 'rider's first name
cell.Offset("B" & Row()).Copy (SheetTarget.Range("B" & LastRow)) 'rider's last name
cell.Offset("C" & Row()).Copy (SheetTarget.Range("C" & LastRow)) 'horse name
cell.Offset("E" & Row()).Copy (SheetTarget.Range("D" & LastRow)) 'horse ID number
End If
Next HorseNumber
End If
Next cell
End If
End Sub
Sheet name: "Registration" (The sub will reside in this sheet module)
*note: Cells A1, B1, C1, D1, and E1 are the only cells in the whole sheet that aren't dynamic. All other cell values change daily.
[TABLE="width: 500"]
<tbody>[TR]
[TD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D]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]ACE[/TD]
[TD][/TD]
[TD]22[/TD]
[TD]Youth[/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD]Youth[/TD]
[TD]Youth[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD]JOE[/TD]
[TD]JOHNSON[/TD]
[TD]JACKO[/TD]
[TD][/TD]
[TD]88[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Jack Benny[/TD]
[/TR]
</tbody>[/TABLE]
The purpose of the sub() is to check the event sheets for the existence of a proper rider and horse entry... kind of self explanatory, but I'm showing the sheets after the sub runs for clarity...
Sheet name: "Adult POLES" (one of 21 possible division & event sheet names)
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]FIRST NAME[/TD]
[TD]LAST NAME[/TD]
[TD]HORSE NAME[/TD]
[TD]HORSE TAG #[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]SUSIE[/TD]
[TD]SMITH[/TD]
[TD]VIPER[/TD]
[TD]55[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]SALLY[/TD]
[TD]SMITH[/TD]
[TD]SABER[/TD]
[TD]41[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Sheet name: "Youth BALL AND CHAIN" (Another of 21 possible division & event sheet names)
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]FIRST NAME[/TD]
[TD]LAST NAME[/TD]
[TD]HORSE NAME[/TD]
[TD]HORSE TAG #[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]KARMA[/TD]
[TD]29[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]KAREN[/TD]
[TD]MILLER[/TD]
[TD]ACE[/TD]
[TD]22[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]70[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Many thanks to those who took the time to read, and bigger thanks to anyone who can help get me on track !