LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
BQ BQ is offline
external usenet poster
 
Posts: 1
Default Comparing Worksheet Names

I can't figure out why my Statements:
If Worksheets(Usersheet).Name < wsSheet.Name Then
and
If Worksheets(Usersheet).Name = wsSheet.Name Then
don't work.

This code is supposed to highlight the dependents on all
sheets of the selected cell, but it doesn't compare
correctly and it highlights all the cells without regard to
the Sheet the the cell came from. If you can help and
provide explainations of what I did wrong and how I can
improve it, I would be very thankful.




Private Sub btnHighlight_Click()

Dim wsSheet As Worksheet
Dim FirstCol, LastCol, FirstRow, LastRow As Long
Dim rng As Range
Dim MyCell As String

Set Usersheet = ActiveSheet

FirstCol = 1
FirstRow = 1


If txtFormBox.Text < "" Then
'FINDS BOTTOM RIGHT CELLS
If WorksheetFunction.CountA(Cells) 0 Then
'Search for any entry, by searching backwards
by Rows.
LastRow = Cells.Find(What:="*", After:=[A1],
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards
by Columns.
LastCol = Cells.Find(What:="*", After:=[A1],
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End If

For i = FirstCol To LastCol
For j = FirstRow To LastRow
On Error Resume Next
If InStr(Cells(j, i).Formula,
txtFormBox.Text) 0 Then
If rng Is Nothing Then
Set rng = Cells(j, i)
End If
Set rng = Union(rng, Cells(j, i))
End If
On Error GoTo 0
Next
Next

rng.Select
Set rng = Nothing


Else


MyCell = Selection.Address


If InStr(MyCell, ",") = 0 Then
If InStr(MyCell, ":") 0 Then
MyCell = Replace(MyCell, "$", "")
MyCell = Mid$(MyCell, 1, InStr(1, MyCell,
":") - 1)
ElseIf InStr(MyCell, ":") = 0 Then
MyCell = Replace(MyCell, "$", "")
End If

On Error Resume Next
For Each wsSheet In Worksheets
wsSheet.Activate

If Usersheet.Name < wsSheet.Name Then
Range("a1").Select
End If


If WorksheetFunction.CountA(Cells) 0 Then
LastRow = Cells.Find(What:="*",
After:=[A1], SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row
LastCol = Cells.Find(What:="*",
After:=[A1], SearchOrder:=xlByColumns,
SearchDirection:=xlPrevious).Column
End If


For i = FirstCol To LastCol
For j = FirstRow To LastRow
If Worksheets(Usersheet).Name =
wsSheet.Name Then
If InStr(1,
Replace(Cells(j, i).Formula, "$", ""), MyCell) 0 Then
If rng Is Nothing Then
Set rng = Cells(j, i)
End If
Set rng = Union(rng,
Cells(j, i))
End If
End If


If Worksheets(Usersheet).Name
< wsSheet.Name Then
If InStr(1,
Replace(Cells(j, i).Formula, "$", ""), "'" & wsSheet.Name &
"'!" & MyCell) 0 Then
If rng Is Nothing Then
Set rng = Cells(j, i)
End If
Set rng = Union(rng,
Cells(j, i))
End If
End If
Next
Next

If Usersheet.Name < wsSheet.Name Then
Application.Goto
Reference:=Range(ActiveCell.Address), Scroll:=True
End If

rng.Select
Set rng = Nothing

Next wsSheet

On Error GoTo 0
Set wSheet = Nothing

End If
End If
End Sub
 
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
comparing two lists of last names rbentzlin Excel Worksheet Functions 6 May 19th 08 04:13 AM
Comparing one column of names to another Kim Excel Worksheet Functions 1 October 18th 07 06:35 PM
Comparing two names Mike Excel Worksheet Functions 3 July 11th 07 05:12 PM
Comparing a column of names lorik Excel Worksheet Functions 1 March 30th 07 09:39 PM
comparing names in a list ferde Excel Discussion (Misc queries) 6 March 22nd 06 05:11 AM


All times are GMT +1. The time now is 02:20 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"