標題: choose and union 疑問 [打印本頁] 作者: jntseng 時間: 2010-8-8 20:37 標題: choose and union 疑問
在VBA 程式中 使用set n=choose(h,union(y,x),union(y1,x),union(y2,x)) ,執行時,此地方會有問題,請教哪裡有問題
詳細程式如下:
Dim x As Range, Y As Range, rng As Range, r As Long '宣告變數
Dim y1 As Range, y2 As Range
For h = 1 To 3
r = Cells(65536, 52 + h).End(xlUp).Row '取的A欄最大列位
Set m = Choose(h, Y, y1, y2)
Set rng = Range("ba2:ba" & r) '取得資料範圍
For Each x In rng '資料範圍內每一儲存格
If x = "" Then '若儲存格值為 ""
If m Is Nothing Then 'Y若不存在
Set m = x '將Y設定為x
Else '若Y存在
Set n = Choose(h, "Union(Y, x)", "Union(y1, x)", "Union(y2, x)")
m = n
End If
End If
Next
If Not m Is Nothing Then m.Delete (xlUp) '若Y存在將Y刪除
Next作者: Hsieh 時間: 2010-8-8 23:04
Set n = Choose(h, "Union(Y, x)", "Union(y1, x)", "Union(y2, x)")
這樣是字串"Union(Y, x)", "Union(y1, x)", "Union(y2, x)"
用SET就出錯
set n=choose(h,union(y,x),union(y1,x),union(y2,x))
基本語法是沒錯,但是一旦x,y,y1,y2其中又一個是nothing也會出錯作者: jntseng 時間: 2010-8-8 23:28