jmh2008
New Member
- Joined
- Sep 4, 2009
- Messages
- 42
Can someone tell me how to fix this? I'm very new and can't figure it out. Thanks,
"Block if without End if"
Option Explicit
Sub FindMe()
Dim sCol
Dim c As Range
Dim msg As Long
Dim rng As Range
Dim roe As Long
Dim LastCol As Long
Dim LastRow As Long
Dim ToFind As String
Dim fRegion As String
Dim finstructor As String
Dim fExpertise As String
Dim fFormat As String
Dim fTravel As String
Dim fProgram As String
Dim fONA As String
Dim shtDest As Worksheet
Dim shtSource As Worksheet
'Sheet to put to
Set shtDest = Sheets(shtSearch)
'Sheet to look in
Set shtSource = Sheets(shtCollection)
'Use
With shtDest
'Get what to look for
If .Range("Region") <> "" Then
'Column to look in
sCol = ColRegion
'What to look for
ToFind = .Range("Region")
'Go search
GoTo SearchMe
ElseIf .Range("Program") <> "" Then
'Column to look in
sCol = ColProgram
'What to look for
ToFind = .Range("Program")
'Go search
GoTo SearchMe
ElseIf .Range("Instructor") <> "" Then
'Column to look in
sCol = ColInstructor
'What to look for
ToFind = .Range("Instructor")
'Go search
GoTo SearchMe
ElseIf .Range("Expertise") <> "" Then
'Column to look in
sCol = ColExpertise
'What to look for
ToFind = .Range("Expertise")
'Go search
GoTo SearchMe
ElseIf .Range("ONA") <> "" Then
'Column to look in
sCol = ColONA
'What to look for
ToFind = .Range("ONA")
'Go search
GoTo SearchMe
ElseIf .Range("Travel") <> "" Then
'Column to look in
sCol = ColTravel
'What to look for
ToFind = .Range("Travel")
'Go search
GoTo SearchMe
Else
'No data to find
msg = MsgBox("No data to find.", vbExclamation, " Try again!")
GoTo endo
End If
End With
SearchMe:
'Use
With shtSource
'Get last row of data
LastRow = .Cells(Rows.Count, sCol).End(xlUp).Row
'Where to look
If sCol = ColProgram Then
'All Program cols
Else
'One col
Set rng = .Range(Cells(2, sCol).Address, Cells(LastRow, sCol).Address)
End If
'Find it
Set c = rng.Find(ToFind, LookIn:=xlValues)
'If found
If Not c Is Nothing Then
Do
'Get row found in
roe = c.Row
'clear then put found info
shtDest.Range("Region") = ""
shtDest.Range("Region") = .Cells(roe, ColRegion)
'Clear then put column where found
shtDest.Range("Program") = ""
'If looking for Program
If sCol = ColProgram Then
'Put column where found
shtDest.Range("Program") = c.Value
Else
'Put first Program
shtDest.Range("Program") = .Cells(roe, ColProgram)
End If
shtDest.Range("Instructor") = ""
shtDest.Range("Instructor") = .Cells(roe, ColInstructor)
shtDest.Range("Expertise") = ""
shtDest.Range("Expertise") = .Cells(roe, ColExpertise)
shtDest.Range("ONA") = ""
shtDest.Range("ONA") = .Cells(roe, ColONA)
shtDest.Range("Travel") = ""
shtDest.Range("Travel") = .Cells(roe, ColTravel)
shtDest.Range("Resume") = ""
shtDest.Range("Resume") = .Cells(roe, ColResume)
shtDest.Range("Outline") = ""
shtDest.Range("Outline") = .Cells(roe, ColOutline)
shtDest.Range("Email") = ""
shtDest.Range("Email") = .Cells(roe, ColEmail)
'Find next one?
msg = MsgBox("Find next one?", vbQuestion + vbYesNo, " Again?")
If msg <> 6 Then GoTo endo
'Do all until back at beginning
'All done
msg = MsgBox("All found.", vbExclamation, "Done.")
GoTo endo
'Not found
msg = MsgBox("Not found.", vbExclamation, "Try again!")
GoTo endo
Loop
If msg <> 6 Then GoTo endo
'No data, come here
endo:
'Cleanup
Set rng = Nothing
Set shtDest = Nothing
Set shtSource = Nothing
End Sub
Sub Clear()
Dim sht As Worksheet
Set sht = Sheets(shtSearch)
With sht
'Clear the named ranges
.Range("Region").ClearContents
.Range("Program").ClearContents
.Range("Instructor").ClearContents
.Range("Expertise").ClearContents
.Range("ONA").ClearContents
.Range("Travel").ClearContents
.Range("Resume").ClearContents
.Range("Outline").ClearContents
.Range("Email").ClearContents
End With
'Cleanup
Set sht = Nothing
End Sub
"Block if without End if"
Option Explicit
Sub FindMe()
Dim sCol
Dim c As Range
Dim msg As Long
Dim rng As Range
Dim roe As Long
Dim LastCol As Long
Dim LastRow As Long
Dim ToFind As String
Dim fRegion As String
Dim finstructor As String
Dim fExpertise As String
Dim fFormat As String
Dim fTravel As String
Dim fProgram As String
Dim fONA As String
Dim shtDest As Worksheet
Dim shtSource As Worksheet
'Sheet to put to
Set shtDest = Sheets(shtSearch)
'Sheet to look in
Set shtSource = Sheets(shtCollection)
'Use
With shtDest
'Get what to look for
If .Range("Region") <> "" Then
'Column to look in
sCol = ColRegion
'What to look for
ToFind = .Range("Region")
'Go search
GoTo SearchMe
ElseIf .Range("Program") <> "" Then
'Column to look in
sCol = ColProgram
'What to look for
ToFind = .Range("Program")
'Go search
GoTo SearchMe
ElseIf .Range("Instructor") <> "" Then
'Column to look in
sCol = ColInstructor
'What to look for
ToFind = .Range("Instructor")
'Go search
GoTo SearchMe
ElseIf .Range("Expertise") <> "" Then
'Column to look in
sCol = ColExpertise
'What to look for
ToFind = .Range("Expertise")
'Go search
GoTo SearchMe
ElseIf .Range("ONA") <> "" Then
'Column to look in
sCol = ColONA
'What to look for
ToFind = .Range("ONA")
'Go search
GoTo SearchMe
ElseIf .Range("Travel") <> "" Then
'Column to look in
sCol = ColTravel
'What to look for
ToFind = .Range("Travel")
'Go search
GoTo SearchMe
Else
'No data to find
msg = MsgBox("No data to find.", vbExclamation, " Try again!")
GoTo endo
End If
End With
SearchMe:
'Use
With shtSource
'Get last row of data
LastRow = .Cells(Rows.Count, sCol).End(xlUp).Row
'Where to look
If sCol = ColProgram Then
'All Program cols
Else
'One col
Set rng = .Range(Cells(2, sCol).Address, Cells(LastRow, sCol).Address)
End If
'Find it
Set c = rng.Find(ToFind, LookIn:=xlValues)
'If found
If Not c Is Nothing Then
Do
'Get row found in
roe = c.Row
'clear then put found info
shtDest.Range("Region") = ""
shtDest.Range("Region") = .Cells(roe, ColRegion)
'Clear then put column where found
shtDest.Range("Program") = ""
'If looking for Program
If sCol = ColProgram Then
'Put column where found
shtDest.Range("Program") = c.Value
Else
'Put first Program
shtDest.Range("Program") = .Cells(roe, ColProgram)
End If
shtDest.Range("Instructor") = ""
shtDest.Range("Instructor") = .Cells(roe, ColInstructor)
shtDest.Range("Expertise") = ""
shtDest.Range("Expertise") = .Cells(roe, ColExpertise)
shtDest.Range("ONA") = ""
shtDest.Range("ONA") = .Cells(roe, ColONA)
shtDest.Range("Travel") = ""
shtDest.Range("Travel") = .Cells(roe, ColTravel)
shtDest.Range("Resume") = ""
shtDest.Range("Resume") = .Cells(roe, ColResume)
shtDest.Range("Outline") = ""
shtDest.Range("Outline") = .Cells(roe, ColOutline)
shtDest.Range("Email") = ""
shtDest.Range("Email") = .Cells(roe, ColEmail)
'Find next one?
msg = MsgBox("Find next one?", vbQuestion + vbYesNo, " Again?")
If msg <> 6 Then GoTo endo
'Do all until back at beginning
'All done
msg = MsgBox("All found.", vbExclamation, "Done.")
GoTo endo
'Not found
msg = MsgBox("Not found.", vbExclamation, "Try again!")
GoTo endo
Loop
If msg <> 6 Then GoTo endo
'No data, come here
endo:
'Cleanup
Set rng = Nothing
Set shtDest = Nothing
Set shtSource = Nothing
End Sub
Sub Clear()
Dim sht As Worksheet
Set sht = Sheets(shtSearch)
With sht
'Clear the named ranges
.Range("Region").ClearContents
.Range("Program").ClearContents
.Range("Instructor").ClearContents
.Range("Expertise").ClearContents
.Range("ONA").ClearContents
.Range("Travel").ClearContents
.Range("Resume").ClearContents
.Range("Outline").ClearContents
.Range("Email").ClearContents
End With
'Cleanup
Set sht = Nothing
End Sub