本文主要是介绍【精华】【Excel VBA】选中相同,并高亮显示,选区交集,移动选区,结果动态显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考:VBA 选择单元格的语句 http://blog.csdn.net/fenghome/article/details/10416743
效果:选中NN(相同内容)上的中文
代码:
1,动态高亮显示
2,选择高亮区域,计算交集处中文选区
3,结果动态显示到固定位置(未完成)
1,
Private Sub Worksheet_SelectionChange(ByVal Target As Range)Dim rng As RangeSet rng = UsedRangeIf Target.Count > 1 ThenSet Target = Target.Cells(1)End IfIf Application.Intersect(Target, rng) Is Nothing Or Target.Value = "" Then Exit SubDim C As RangeFor Each ws In WorksheetsSet rng = ws.UsedRangerng.Interior.ColorIndex = xlNoneFor Each C In rngIf C.Value = Target.Value Thenws.UsedRange.Columns(C.Column).Interior.ColorIndex = 36End IfNextNext
End Sub
2,
Sub test()Dim rng As Range, cel As Range, A As Range, B As Range, C As RangeFor Each cel In ActiveSheet.UsedRange.CellsIf cel.Interior.Color = 10092543 ThenSet rng = celExit ForEnd IfNextFor Each cel In ActiveSheet.UsedRange.CellsIf cel.Interior.Color = 10092543 Then Set rng = Union(rng, cel)Nextrng.SelectEndRange = "A2"Set B = Range(EndRange, Range(EndRange).End(xlEnd))Intersect(rng, B).SelectEnd Sub
3,
Public Sub sss()Dim str As String, temp As String, CXrng As Range, XRrng As RangeSet CXrng = SelectionFor Each XRrng In CXrngstr = str & XRrng.ValueNext[a14] = strEnd Sub
这篇关于【精华】【Excel VBA】选中相同,并高亮显示,选区交集,移动选区,结果动态显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!