Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
comparing two lists of last names | Excel Worksheet Functions | |||
Comparing one column of names to another | Excel Worksheet Functions | |||
Comparing two names | Excel Worksheet Functions | |||
Comparing a column of names | Excel Worksheet Functions | |||
comparing names in a list | Excel Discussion (Misc queries) |