Elle Bee Dee
New Member
- Joined
- May 5, 2011
- Messages
- 2
I have been working on trying to make a macro that will check if a value is in a list selected based on a header row match.
The workbook is set up so i have the "TableSheet" which is something comperable to the table below, on the "HeaderSelectionSheet" a selection that matches the header rows of the table, and on "Sheet1" that gets copied to "Sheet3" I want to check the vaules in column C to make sure that thevalue is in the table under the header row selected.
Below i have pasted the table and the code.
I got the macro below to work but i will be adding more columns to the table and it would be great if i could have it work for however many columns are in the table.
Any Suggestions or help would be greatly appreciated.
Dances, Art, Sports, Philanthropy, Other
Jazz, Paiting, Basketball, Amnesty International, Chess Club
Tap, Sculpture, Baseball, Habitat for Humanity, Drama
Modern, Drawing, Football, Food Bank, Academic Decath
Ballet,, Soccer, SADD, Mathletes
,, Track , , Student Council
____
'Check
'Delete Check sheet if it exists
Application.DisplayAlerts = False
On Error Resume Next
Sheets("Sheet3").Delete
Application.DisplayAlerts = True
'Copy the pasted data
Sheets("Sheet1").Select
Sheets("Sheet1").Copy After:=Sheets(4)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Name = "Sheet3"
Application.Sheets("Sheet3").Activate
EndRowPasted = Cells(Rows.Count, "A").End(xlUp).Row
counter = 2
Check = Cells(counter, "G").Value
'Check to see that the data matches the header selection
Range("G2").Value = "=MATCH(Sheet3!C2,CHOOSE(MATCH(HeaderSelection!$B$13,TableSheet!$A$2:$F$2),TableSheet!$A$2:$A$9,TableSheet!$B$2:$B$9,TableSheet!$C$2:$C$9,TableSheet!$D$2:$D$9,TableSheet!$E$2:$E$9,TableSheet!$F$2:$F$9,TableSheet!$G$2:$G$9,TableSheet!$H$2:$H$9,TableSheet!$I$2:$I$9,TableSheet!$J$2:$J$9),0)"
Range("G2").Select
Selection.Copy
Range("G3:G" & EndRowPasted).Select
ActiveSheet.Paste
'If there is a #N/A error Give message and exit macro
Do While counter < EndRowPasted
Cells(counter, "G").Select
If Application.IsNA(ActiveCell.Value) Then
MsgBox "EPIC FAIL"
Exit Sub
Else
counter = counter + 1
End If
Loop
'Delete Check sheet
Application.DisplayAlerts = False
Sheets("Sheet3").Delete
Application.DisplayAlerts = True
'End Check
The workbook is set up so i have the "TableSheet" which is something comperable to the table below, on the "HeaderSelectionSheet" a selection that matches the header rows of the table, and on "Sheet1" that gets copied to "Sheet3" I want to check the vaules in column C to make sure that thevalue is in the table under the header row selected.
Below i have pasted the table and the code.
I got the macro below to work but i will be adding more columns to the table and it would be great if i could have it work for however many columns are in the table.
Any Suggestions or help would be greatly appreciated.
Dances, Art, Sports, Philanthropy, Other
Jazz, Paiting, Basketball, Amnesty International, Chess Club
Tap, Sculpture, Baseball, Habitat for Humanity, Drama
Modern, Drawing, Football, Food Bank, Academic Decath
Ballet,, Soccer, SADD, Mathletes
,, Track , , Student Council
____
'Check
'Delete Check sheet if it exists
Application.DisplayAlerts = False
On Error Resume Next
Sheets("Sheet3").Delete
Application.DisplayAlerts = True
'Copy the pasted data
Sheets("Sheet1").Select
Sheets("Sheet1").Copy After:=Sheets(4)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Name = "Sheet3"
Application.Sheets("Sheet3").Activate
EndRowPasted = Cells(Rows.Count, "A").End(xlUp).Row
counter = 2
Check = Cells(counter, "G").Value
'Check to see that the data matches the header selection
Range("G2").Value = "=MATCH(Sheet3!C2,CHOOSE(MATCH(HeaderSelection!$B$13,TableSheet!$A$2:$F$2),TableSheet!$A$2:$A$9,TableSheet!$B$2:$B$9,TableSheet!$C$2:$C$9,TableSheet!$D$2:$D$9,TableSheet!$E$2:$E$9,TableSheet!$F$2:$F$9,TableSheet!$G$2:$G$9,TableSheet!$H$2:$H$9,TableSheet!$I$2:$I$9,TableSheet!$J$2:$J$9),0)"
Range("G2").Select
Selection.Copy
Range("G3:G" & EndRowPasted).Select
ActiveSheet.Paste
'If there is a #N/A error Give message and exit macro
Do While counter < EndRowPasted
Cells(counter, "G").Select
If Application.IsNA(ActiveCell.Value) Then
MsgBox "EPIC FAIL"
Exit Sub
Else
counter = counter + 1
End If
Loop
'Delete Check sheet
Application.DisplayAlerts = False
Sheets("Sheet3").Delete
Application.DisplayAlerts = True
'End Check