热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

摆脱。在VBA代码中选择-Getridof.SelectinVBACode

Iwouldliketogetridofthesht2.Selectandsht2.Range(B2).Selectinthecodebelow.Istherea

I would like to get rid of the sht2.Select and sht2.Range("B2").Select in the code below. Is there a way to do this?

我想摆脱sht2.Select和sht2.Range(“B2”)。在下面的代码中选择。有没有办法做到这一点?

Sub Remaining()

Dim sht2 As Worksheet    
Dim cell As Range

Set sht2 = ThisWorkbook.Worksheets("Sheet2")

sht2.Select
sht2.Range("B2").Select    
With sht2
    For Each cell In .Range("B2", Cells(Rows.Count, "B").End(xlUp))
        If .Range("A:A").Find(What:=cell.Value2, LookAt:=xlWhole) Is Nothing Then
           Intersect(.UsedRange, cell.EntireRow).Offset(, 1).Copy Sheets("Sheet1").Cells(Rows.Count, "L").End(xlUp).Offset(1)
           cell.Interior.Color = vbYellow
       End If
    Next cell
End With

End Sub

1 个解决方案

#1


6  

Sub Remaining()

    Dim sht2 As Worksheet
    Dim cell As Range

    Set sht2 = ThisWorkbook.Worksheets("Sheet2")

    With sht2
        'A few fixes in the following line to make sure everything
        '   is referencing the correct sheet
        For Each cell In .Range(.Range("B2"), .Cells(.Rows.Count, "B").End(xlUp))
            If .Range("A:A").Find(What:=cell.Value2, LookAt:=xlWhole) Is Nothing Then
               Intersect(.UsedRange, cell.EntireRow).Offset(, 1).Copy _
                      Sheets("Sheet1").Cells(Rows.Count, "L").End(xlUp).Offset(1)
               cell.Interior.Color = vbYellow
           End If
        Next cell
    End With

End Sub

推荐阅读
author-avatar
fghnh102_441
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有