想要一个区域对比的执行代码,现在有两个区域,A区域(比如C3:C50,这区域是不固定的,所以区域只能提示选择)里从第一个单元格依次去B区域(如H10:H25这区域也是固定的)里找查有没有想同的值,如果有就把本单元格加黄色底纹,如:C3里的值在H10:H25里找不到就不处理,如里C3里的值在H10:H25里有出现,则把C3加上黄色底纹。请高手给个代码!
如同这样的情况区域大小也不一样
excel区域对比VBA执行代码
答案:2 悬赏:0 手机版
解决时间 2021-04-05 01:31
- 提问者网友:玫瑰园
- 2021-04-04 06:17
最佳答案
- 五星知识达人网友:鱼忧
- 2021-04-04 07:27
Sub s()
Dim rg1 As Range, rg2 As Range, c As Range, d As Object
Set rg1 = Application.InputBox("请输入区域A", , , , , , , 8)
Set rg2 = Application.InputBox("请输入区域B", , , , , , , 8)
Set d = CreateObject("scripting.dictionary")
For Each c In rg2
d(c.Text) = ""
Next
For Each c In rg1
If d.exists(c.Text) Then
c.Interior.Color = vbYellow
End If
Next
End Sub
Dim rg1 As Range, rg2 As Range, c As Range, d As Object
Set rg1 = Application.InputBox("请输入区域A", , , , , , , 8)
Set rg2 = Application.InputBox("请输入区域B", , , , , , , 8)
Set d = CreateObject("scripting.dictionary")
For Each c In rg2
d(c.Text) = ""
Next
For Each c In rg1
If d.exists(c.Text) Then
c.Interior.Color = vbYellow
End If
Next
End Sub
全部回答
- 1楼网友:胯下狙击手
- 2021-04-04 08:01
sub test()
activeworkbook.worksheets("sheet1").sort.sortfields.clear
activeworkbook.worksheets("sheet1").sort.sortfields.add key:=range("c:c"), _
sorton:=xlsortonvalues, order:=xldescending, dataoption:=xlsortnormal
activeworkbook.worksheets("sheet1").sort.sortfields.add key:=range("d:d"), _
sorton:=xlsortonvalues, order:=xlascending, dataoption:=xlsortnormal
with activeworkbook.worksheets("sheet1").sort
.setrange range("c:d")
.header = xlyes
.matchcase = false
.orientation = xltoptobottom
.sortmethod = xlpinyin
.apply
end with
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
正方形一边上任一点到这个正方形两条对角线的 |
阴历怎么看 ? |