ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA n00b :\ (https://www.excelbanter.com/excel-programming/317012-vba-n00b-%5C.html)

skattyd

VBA n00b :\
 

i'm just starting out with VBA i have to write a code to search throug
a database in excel and highlight people in red that you put into th
input box. How can i make it if the persons name is not found come u
with a message box stating so and if it is found to just end. here i
my code so for i just cant figure it out please help!!


Sub SuperHighlight()
Dim strName As String

strName = InputBox("Type in the name of the sales representativ
you wish to be highlighted")

Application.Goto Reference:="FirstDate"
Do Until ActiveCell = ""
ActiveCell.Range("A1:D1").Select
If ActiveCell.Offset(0, 1) = strName Then
Selection.Font.ColorIndex = 3
End If
ActiveCell.Offset(1, 0).Select

Loop

If strName = "" Then MsgBox "User Not Found Re-Type Name"


End Su

--
skatty
-----------------------------------------------------------------------
skattyd's Profile: http://www.excelforum.com/member.php...fo&userid=1654
View this thread: http://www.excelforum.com/showthread.php?threadid=31394


Bob Phillips[_6_]

VBA n00b :\
 
Not how I would do it, but using your code, this is one way

Sub SuperHighlight()
Dim strName As String
Dim fFound as boolean

strName = InputBox("Type in the name of the sales representative
you wish to be highlighted")

Application.Goto Reference:="FirstDate"
Do Until ActiveCell = ""
ActiveCell.Range("A1:D1").Select
If ActiveCell.Offset(0, 1) = strName Then
Selection.Font.ColorIndex = 3
fFound = "True"
End If
ActiveCell.Offset(1, 0).Select

Loop

If Not fFound Then MsgBox strName & " not found"
If strName = "" Then MsgBox "User Not Found Re-Type Name"


End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"skattyd" wrote in message
...

i'm just starting out with VBA i have to write a code to search through
a database in excel and highlight people in red that you put into the
input box. How can i make it if the persons name is not found come up
with a message box stating so and if it is found to just end. here is
my code so for i just cant figure it out please help!!


Sub SuperHighlight()
Dim strName As String

strName = InputBox("Type in the name of the sales representative
you wish to be highlighted")

Application.Goto Reference:="FirstDate"
Do Until ActiveCell = ""
ActiveCell.Range("A1:D1").Select
If ActiveCell.Offset(0, 1) = strName Then
Selection.Font.ColorIndex = 3
End If
ActiveCell.Offset(1, 0).Select

Loop

If strName = "" Then MsgBox "User Not Found Re-Type Name"


End Sub


--
skattyd
------------------------------------------------------------------------
skattyd's Profile:

http://www.excelforum.com/member.php...o&userid=16545
View this thread: http://www.excelforum.com/showthread...hreadid=313946




Jim Thomlinson[_3_]

VBA n00b :\
 
You need to set a flag when you have found a name

blnFoundName = false
Sub SuperHighlight()
Dim strName As String
Dim blnFoundName as boolean

blnFoundName = false
strName = InputBox("Type in the name of the sales representative
you wish to be highlighted")

Application.Goto Reference:="FirstDate"
Do Until ActiveCell = "" or blnFoundName = true
ActiveCell.Range("A1:D1").Select
If ActiveCell.Offset(0, 1) = strName Then
Selection.Font.ColorIndex = 3
blnFoundName = true
End If
ActiveCell.Offset(1, 0).Select

Loop
if blnFoundName = false then
msgbox strName & " not Found"
endif

If strName = "" Then MsgBox "User Not Found Re-Type Name"


End Sub


"skattyd" wrote: Sub SuperHighlight()
Dim strName As String

strName = InputBox("Type in the name of the sales representative
you wish to be highlighted")

Application.Goto Reference:="FirstDate"
Do Until ActiveCell = ""
ActiveCell.Range("A1:D1").Select
If ActiveCell.Offset(0, 1) = strName Then
Selection.Font.ColorIndex = 3
End If
ActiveCell.Offset(1, 0).Select

Loop

If strName = "" Then MsgBox "User Not Found Re-Type Name"


End Sub




i'm just starting out with VBA i have to write a code to search through
a database in excel and highlight people in red that you put into the
input box. How can i make it if the persons name is not found come up
with a message box stating so and if it is found to just end. here is
my code so for i just cant figure it out please help!!




--
skattyd
------------------------------------------------------------------------
skattyd's Profile: http://www.excelforum.com/member.php...o&userid=16545
View this thread: http://www.excelforum.com/showthread...hreadid=313946




All times are GMT +1. The time now is 06:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com