【发布时间】:2021-11-05 20:27:28
【问题描述】:
您好,我是 VBA 新手,想知道为什么当我重置范围时,范围内的所有内容都会删除。我们不应该在 VBA 中重新分配范围吗?有问题的行是supervisor_range = .Range(Cells(2, 1), .Range("A" & .Rows.Count).End(xlUp)) 下图中的所有名称都将被删除。
Sub remove()
Dim supervisorsheet As Worksheet
Set supervisorsheet = Worksheets("supervisor")
Dim supervisor_range As Range
Dim cell As Range
last_row = supervisorsheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Set supervisor_range = supervisorsheet.Range(Cells(2, 1), Cells(last_row, 1))
supervisor_range.RemoveDuplicates Columns:=1, Header:=xlNo
With supervisorsheet
supervisor_range = .Range(Cells(2, 1), .Range("A" & .Rows.Count).End(xlUp))
End With
End Sub
【问题讨论】:
标签: vba range declaration