基础操作就可完成的:
选中区域/按F5/定位/定位条件/常量/确定
干吗非要VBA?
Sub s()
Set rg = [a39:j1039]
i = 1
Do While rg.Item(i) = ""
i = i + 1
If i = rg.Count Then Exit Do
Loop
If rg.Item(i) <> "" Then
Set rg1 = rg.Item(i)
For j = i To rg.Count
If rg.Item(j) <> "" Then
Set rg1 = Union(rg1, rg.Item(j))
End If
Next
rg1.Select
End If
End Sub
For i = 1 To 65536
If Cells(i, 3) = "" Then
Set s = Range(Cells(i, 1), Cells(i, 4))
Else
Set s = Union(s, Range(Cells(i, 1), Cells(i, 4)))
核心部分的代码大致是如此的
逻辑思路就是:先循环,循环的同时进行判断,将判断为非空的单元格联合起来,最后选中这批单元格