2017-07-07 57 views
0

我有一个包含10个机器零件的工作簿。在表10中,我将列出关键部分。我想引用A-I列中表10中的所有信息,然后我想要突出显示工作簿中每个其他实例的行。例如, 。如果我在工作表10上有SAP编号“829131”,我希望每个在整个工作簿中都有SAP编号“829131”的行突出显示。在不同的表格之间交叉引用Excel数据并突出显示重复项

我不知道该从哪里开始。所以希望你能帮助我。

我在网上发现了一些我认为可以工作的东西,但它只引用了活动单元格,我无法弄清楚如何使它引用我需要的范围。

Sub CriticalSpare() 

'Code will highlight all rows in all open workbooks 
'which contain the same text as active cell 
Dim wb As Workbook 
Dim ws As Worksheet 
Dim fString As String 
Dim firstAdd As String 
Dim fCell As Range 
Dim myCol As Long 

'The item to look for is the active cell 
fString = ActiveCell.Value 

'Highlight things in red 
myCol = 41 


'Don't run on a blank cell 
If fString = "" Then 
    MsgBox "No value given" 
    Exit Sub 
End If 

Application.ScreenUpdating = False 
'Loop through all workbooks... 
For Each wb In Application.Workbooks 
'...and all worksheets 
    For Each ws In wb.Worksheets 
     Set fCell = Nothing 
      firstAdd = "" 
     With ws.Cells 
      'looking for the desired value 
      Set fCell = .Find(fString) 
      If Not fCell Is Nothing Then 
        firstAdd = fCell.Address 
        Do 
         'and if found, highlight the row 
        fCell.Interior.ColorIndex = myCol 
         Set fCell = .FindNext(fCell) 
        Loop Until fCell.Address = firstAdd 
       End If 
     End With 
     Next ws 
Next wb 
Application.ScreenUpdating = True 

End Sub 
+0

你尝试过什么:因为它处理选择更改事件

以下过程突出了整个行和列在每个新小区的选择将其粘贴到的ThisWorkbook代码?听起来像条件​​格式会起作用。 – BruceWayne

+0

我在网上阅读了一些东西之后想过使用条件格式,但是我找不到适合我的情况的任何东西。如果那能行得通,我愿意尝试。我会在原来的帖子中添加一个编辑,以完成我已经完成的工作。 –

+0

这里的要求与其他几十个CF Qs在要求上没有根本的区别,只是它对每张纸都是单独要求的。 – pnuts

回答

0

也许您可以编辑此代码以满足您的需求。

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _ 
ByVal Target As Range) 

Dim myRow As Long, myColumn As Long 

myRow = Target.Row 
myColumn = Target.Column 

Sh.Cells.Interior.ColorIndex = 0 
Sh.Rows(myRow).Interior.Color = vbYellow 
Sh.Columns(myColumn).Interior.Color = vbYellow 

End Sub 
相关问题