- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
8#
發表於 2015-3-2 07:02
| 只看該作者
回復 5# PKKO
資料驗證要如何輸入空白,直接清空.- '** 資料驗證選單來源
- '1 資料驗證選單來源是儲存格位置:但需是是同一工作表的儲存格
- 'With Range("d2:d" & allr).Validation
- ' .Delete
- ' .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
- ' xlBetween, Formula1:="=" & Range("A2:A10").Address
- 'End With
-
- '2 資料驗證選單來源用 ","連接的字串
- With Sheets("轉換表")
- myRange = .Range("s2:s" & .Range("s65536").End(xlUp).Row) '資料驗證用
- End With
- '** 陣列轉換成字串
-
- '** Join 函數 傳回一個字串,該字串是透過連結某個陣列中的多個子字串而建立的。
- '** myRange參照儲存格是為二維陣列,需轉成一維陣列方可為Join 函數使用
- 'arr = Join(Application.Transpose(myRange), ",")
-
- '** 跑迴圈取得字串
- 'For Each e In myRange
- ' arr = arr & "," & e
- 'Next
-
- '** Split 函數 傳回一個陳列索引從零開始的一維陣列,它包含指定數目的子字串。
- '** arr = Split(Mid(arr, 2, 10000), ",") '錯誤的用法,因為 arr 傳回陣列,
- '** arr 須是 字串.
-
- '************************************************
-
- With Range("d2:d" & allr).Validation
- .Delete
- .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
- xlBetween, Formula1:=Join(Application.Transpose(myRange), ",") '<- arr
- End With
複製代碼 |
|