|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
探讨探讨:
- Sub del2()
- Dim Dict As Dictionary, Dict1 As Dictionary
- 'Set Dict = New Dictionary
- 'Set Dict1 = New Dictionary
- Set Dict = CreateObject("Scripting.Dictionary")
- Set Dict1 = CreateObject("Scripting.Dictionary")
- Dim Rng As Range, Arr
- Set Rng = Sheet1.Cells(1, 1).CurrentRegion
- 'Debug.Print Rng.Address
- Rng.Select
-
- ' Rrange具有Copyμ等属性¸′并可复制所有单元格格式 ,可操作更直观的验证下,当然 .Address 属性已可以验证确认
- 'For ii = 1 To Rng.Rows.Count
- ' Set Dict(Rng(ii, 2)) = Rng(ii, 1) 'OK
- ' Debug.Print Dict.Items(ii - 1).Address 'OK
- ' Dict.Items(ii - 1).Copy Sheet1.Cells(ii + 1, 18) 'OK
- 'Next ii
-
- For ii = 1 To Rng.Rows.Count
- Dict(Rng(ii, 2)) = Rng(ii, 1) 'OK
- Debug.Print Dict.Items(ii - 1) 'OK
- ' Debug.Print Dict.Items(ii - 1).Address 'NG
- ' Dict.Items(ii - 1).Copy Sheet1.Cells(ii + 1, 18) 'NG
- Next ii
-
- 'For ii = 1 To Rng.Rows.Count
- ' Dict(Rng(ii, 2)) = Rng(ii, 1).Value 'OK
- ' Set Dict(Rng(ii, 2)) = Rng(ii, 1).Value 'OK
- ' Debug.Print Dict.Items(ii - 1) 'OK
- ' Debug.Print Dict.Items(ii - 1).Address 'NG
- ' Dict.Items(ii - 1).Copy Sheet1.Cells(ii + 1, 18) 'NG
- 'Next ii
-
- 'Stop
- For ii = 0 To Dict.Count - 1
- Set Rng = Dict.Items(ii) 'Rng 定义为 Rrange 可否赋值 ,得看 Dict.Items(ii) 是否也是 Rrange
- Debug.Print Rng.Address
- Rng.Copy Sheet1.Cells(ii + 1, 18)
- Next ii
-
- End Sub
复制代码 |
|