Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Search routine needs a little work

Hi all -

My search routine below
I can't seem to figure out how to add a little functionality

1. Currently finds a value and returns the value
should retrun the cell ref such as A36

2. Maybe even better, take the user to the sheet and the cell
and change the interior color of the entire row (A:V) to 36 (soft
yellow)

3. What if the number does not exist in the database?
I'm not sure what to add if the search snippet comes back empty

Thanks much
-goss

Option Explicit

Sub cm_ValidateBeforeWrite()

Dim wbBook As Workbook
Dim wsWrite As Worksheet 'RCM_Write
Dim wsData As Worksheet 'RCM_Data
Dim rngFoundCell As Range
Dim rngToSearch As Range
Dim lngValueToBeFound As Long
Dim lngRows As Long
Dim Msg As Long

With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.ScreenUpdating = False
End With

Set wbBook = ThisWorkbook
Set wsWrite = wbBook.Worksheets("RCM_Write")
Set wsData = wbBook.Worksheets("RCM_Data")

'Refresh the dataset
'cm_GetData

'What to search for
lngValueToBeFound = wsWrite.Range("A2").Value

'Where to search
lngRows = wsData.Range("A65536").End(xlUp).Row
Set rngToSearch = wsData.Range("A2:A" & lngRows)

'Search
Set rngFoundCell = rngToSearch.Find(what:=lngValueToBeFound, _

after:=rngToSearch.Cells(rngToSearch.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole)
'Response
Msg = MsgBox("The RCM_Nmbr is already in use. " & vbCrLf _
& rngFoundCell & ".", vbInformation + vbOKOnly, "Message")


'//Cleanup
Set rngToSearch = Nothing
Set rngFoundCell = Nothing
Set wsData = Nothing
Set wsWrite = Nothing
Set wbBook = Nothing

With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Search routine needs a little work

Untested but this should be close...

Option Explicit

Sub cm_ValidateBeforeWrite()

Dim wbBook As Workbook
Dim wsWrite As Worksheet 'RCM_Write
Dim wsData As Worksheet 'RCM_Data
Dim rngFoundCell As Range
Dim rngToSearch As Range
Dim lngValueToBeFound As Long

With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.ScreenUpdating = False
End With

Set wbBook = ThisWorkbook
Set wsWrite = wbBook.Worksheets("RCM_Write")
Set wsData = wbBook.Worksheets("RCM_Data")

'Refresh the dataset
cm_GetData

'What to search for
lngValueToBeFound = wsWrite.Range("A2").Value

'Where to search
Set rngToSearch = wsData.columns("A")

'Search
Set rngFoundCell = rngToSearch.Find(what:=lngValueToBeFound, _

after:=rngToSearch.Cells(rngToSearch.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole)
if rngfoundcell is nothing then 'check if something was found
'Response
Msg = MsgBox("The RCM_Nmbr is already in use. " & vbCrLf _
& rngFoundCell & ".", vbInformation + vbOKOnly, "Message")
else
wsdata.select
rngfoundcell.entirerow.interior.color = 36
rngfoundcell.select
end if

'//Cleanup
Set rngToSearch = Nothing
Set rngFoundCell = Nothing
Set wsData = Nothing
Set wsWrite = Nothing
Set wbBook = Nothing

With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With

End Sub

--
HTH...

Jim Thomlinson


" wrote:

Hi all -

My search routine below
I can't seem to figure out how to add a little functionality

1. Currently finds a value and returns the value
should retrun the cell ref such as A36

2. Maybe even better, take the user to the sheet and the cell
and change the interior color of the entire row (A:V) to 36 (soft
yellow)

3. What if the number does not exist in the database?
I'm not sure what to add if the search snippet comes back empty

Thanks much
-goss

Option Explicit

Sub cm_ValidateBeforeWrite()

Dim wbBook As Workbook
Dim wsWrite As Worksheet 'RCM_Write
Dim wsData As Worksheet 'RCM_Data
Dim rngFoundCell As Range
Dim rngToSearch As Range
Dim lngValueToBeFound As Long
Dim lngRows As Long
Dim Msg As Long

With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.ScreenUpdating = False
End With

Set wbBook = ThisWorkbook
Set wsWrite = wbBook.Worksheets("RCM_Write")
Set wsData = wbBook.Worksheets("RCM_Data")

'Refresh the dataset
'cm_GetData

'What to search for
lngValueToBeFound = wsWrite.Range("A2").Value

'Where to search
lngRows = wsData.Range("A65536").End(xlUp).Row
Set rngToSearch = wsData.Range("A2:A" & lngRows)

'Search
Set rngFoundCell = rngToSearch.Find(what:=lngValueToBeFound, _

after:=rngToSearch.Cells(rngToSearch.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole)
'Response
Msg = MsgBox("The RCM_Nmbr is already in use. " & vbCrLf _
& rngFoundCell & ".", vbInformation + vbOKOnly, "Message")


'//Cleanup
Set rngToSearch = Nothing
Set rngFoundCell = Nothing
Set wsData = Nothing
Set wsWrite = Nothing
Set wbBook = Nothing

With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Search routine needs a little work

Thanks Jim
Works well.
Two minor things

-code 36 appears to be black at least the row comes back filled black
odd because I ran a little piece of code to return the color index of
the selected cell
So I filled a cell with light yellow, ran the code MsgBox came back
with 36

Any idea the correct index for light yellow or where I could look to
verify?

Thanks
-goss


Jim Thomlinson wrote:
Untested but this should be close...

Option Explicit

Sub cm_ValidateBeforeWrite()

Dim wbBook As Workbook
Dim wsWrite As Worksheet 'RCM_Write
Dim wsData As Worksheet 'RCM_Data
Dim rngFoundCell As Range
Dim rngToSearch As Range
Dim lngValueToBeFound As Long

With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.ScreenUpdating = False
End With

Set wbBook = ThisWorkbook
Set wsWrite = wbBook.Worksheets("RCM_Write")
Set wsData = wbBook.Worksheets("RCM_Data")

'Refresh the dataset
cm_GetData

'What to search for
lngValueToBeFound = wsWrite.Range("A2").Value

'Where to search
Set rngToSearch = wsData.columns("A")

'Search
Set rngFoundCell = rngToSearch.Find(what:=lngValueToBeFound, _

after:=rngToSearch.Cells(rngToSearch.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole)
if rngfoundcell is nothing then 'check if something was found
'Response
Msg = MsgBox("The RCM_Nmbr is already in use. " & vbCrLf _
& rngFoundCell & ".", vbInformation + vbOKOnly, "Message")
else
wsdata.select
rngfoundcell.entirerow.interior.color = 36
rngfoundcell.select
end if

'//Cleanup
Set rngToSearch = Nothing
Set rngFoundCell = Nothing
Set wsData = Nothing
Set wsWrite = Nothing
Set wbBook = Nothing

With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With

End Sub

--
HTH...

Jim Thomlinson


" wrote:

Hi all -

My search routine below
I can't seem to figure out how to add a little functionality

1. Currently finds a value and returns the value
should retrun the cell ref such as A36

2. Maybe even better, take the user to the sheet and the cell
and change the interior color of the entire row (A:V) to 36 (soft
yellow)

3. What if the number does not exist in the database?
I'm not sure what to add if the search snippet comes back empty

Thanks much
-goss

Option Explicit

Sub cm_ValidateBeforeWrite()

Dim wbBook As Workbook
Dim wsWrite As Worksheet 'RCM_Write
Dim wsData As Worksheet 'RCM_Data
Dim rngFoundCell As Range
Dim rngToSearch As Range
Dim lngValueToBeFound As Long
Dim lngRows As Long
Dim Msg As Long

With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.ScreenUpdating = False
End With

Set wbBook = ThisWorkbook
Set wsWrite = wbBook.Worksheets("RCM_Write")
Set wsData = wbBook.Worksheets("RCM_Data")

'Refresh the dataset
'cm_GetData

'What to search for
lngValueToBeFound = wsWrite.Range("A2").Value

'Where to search
lngRows = wsData.Range("A65536").End(xlUp).Row
Set rngToSearch = wsData.Range("A2:A" & lngRows)

'Search
Set rngFoundCell = rngToSearch.Find(what:=lngValueToBeFound, _

after:=rngToSearch.Cells(rngToSearch.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole)
'Response
Msg = MsgBox("The RCM_Nmbr is already in use. " & vbCrLf _
& rngFoundCell & ".", vbInformation + vbOKOnly, "Message")


'//Cleanup
Set rngToSearch = Nothing
Set rngFoundCell = Nothing
Set wsData = Nothing
Set wsWrite = Nothing
Set wbBook = Nothing

With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming work sheet the name as sub-routine that creates it Rich Mogy Excel Worksheet Functions 5 October 6th 08 02:07 PM
Search for month doesn't work for specific months [email protected] Excel Discussion (Misc queries) 3 January 23rd 08 10:14 AM
Dos not work correct "Search" function LInc New Users to Excel 2 July 20th 06 12:49 PM
"Search for files and folders" option doesnot work for 100% ECouwenberg Excel Discussion (Misc queries) 7 January 11th 06 04:50 PM
A search for $ in a formula use to work now it does not work JuneJuly Excel Discussion (Misc queries) 2 November 30th 05 10:13 PM


All times are GMT +1. The time now is 03:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"