[算表] vba选取连续栏用FOR循环

楼主: awwq (ww)   2015-01-02 16:27:51
软件:office excel
版本:2013
小弟刚起步学习VBA看范例想用循环选取连续字段
附上程式
Public Sub 技巧4_002()
Dim myRange As Range
Dim i As Integer
For i = 1 To 3
Set myRange = Columns(i)
myRange.Select
Next i
Set myRange = Nothing
End Sub
上述程式只会选取最后一栏也就是C栏 A和B栏都无法选取
请问先进 逻辑上哪里有错 谢谢
作者: soyoso (我是耀宗)   2015-01-02 18:15:00
可用resize
作者: Catbert (宅男)   2015-01-02 20:50:00
Set myRange = Union(myRange, Columns(i))
作者: soyoso (我是耀宗)   2015-01-02 21:35:00
union?会有错误喔要用要加判断,直接将set myrange=column(i)置换是不行的

Links booklink

Contact Us: admin [ a t ] ucptt.com