標題:
[發問]
COLUMN問題
[打印本頁]
作者:
basarasy
時間:
2011-4-1 22:43
標題:
COLUMN問題
請問大大2個問題.
第1個是圖片中的問題.
第2個是 如果想DEL COLUMN("A:A") 可以把 A:A轉用數字嗎? COLUMN("1:1").DEL
[attach]5209[/attach]
作者:
Hsieh
時間:
2011-4-2 23:35
回復
1#
basarasy
猜想是這樣的意思
Sub Ex()
Dim Ar(), Ay(), Rng As Range, A As Range, s%, j%
Set Rng = [A1:G1]
For Each A In Rng
If A = Application.Max(Rng) Then
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address
Ay(s) = A.Column
s = s + 1
End If
Next
[H1].Resize(, s) = Ay: s = 0: Erase Ar
Set Rng = Nothing
For j = 0 To UBound(Ay)
If Rng Is Nothing Then Set Rng = Cells(2, Ay(j)) Else Set Rng = Union(Rng, Cells(2, Ay(j)))
Next
For r = 2 To Cells(Rows.Count, 1).End(xlUp).Row
For Each A In Rng
If A = Application.Min(Rng) Then
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address
Ay(s) = A.Column
s = s + 1
End If
Next
Cells(r, "H").Resize(, s) = Ay
For j = 0 To UBound(Ay)
Set Rng = Union(Rng, Cells(2, Ay(j)))
Next
s = 0: Erase Ay: Erase Ar
Next
End Sub
複製代碼
另外用數字代替欄位OK的
Columns(1).Delete
作者:
basarasy
時間:
2011-4-3 09:41
回復
2#
Hsieh
謝謝大大的教導.
第1個問題只會出1個COL的數. 這個圖我做了所有可能.
[attach]5224[/attach]
作者:
Hsieh
時間:
2011-4-5 20:07
回復
3#
basarasy
試試看
Sub Ex()
Dim Ar(), Ay(), Rng As Range, A As Range, s%, j%
Set Rng = [A1:G1]
For Each A In Rng
If A = Application.Max(Rng) Then '如果是最大值
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address '記住位址
Ay(s) = A.Column '記住欄位
s = s + 1
End If
Next
s = 0: Erase Ar
Set Rng = Nothing
For j = 0 To UBound(Ay) '最大值的下一格儲存格聯集
If Rng Is Nothing Then Set Rng = Cells(2, Ay(j)) Else Set Rng = Union(Rng, Cells(2, Ay(j)))
Next
For r = 2 To Cells(Rows.Count, 1).End(xlUp).Row '第2列以下迴圈
For Each A In Rng
If A = Application.Min(Rng) Then '如果是最小值
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address '記住位址
Ay(s) = A.Column '記住欄位
s = s + 1
End If
Next
Set Rng = Nothing
For j = 0 To UBound(Ay)
If Rng Is Nothing Then Set Rng = Cells(r, Ay(j)) Else Set Rng = Union(Rng, Cells(r, Ay(j)))
Next
ck = Ay(0)
s = 0: Erase Ay: Erase Ar
Next
[H1] = ck
End Sub
複製代碼
作者:
basarasy
時間:
2011-4-5 20:30
回復
4#
Hsieh
謝謝Hsieh大大.
row1和row2 計算沒有問題.
row3有少少問題.
[attach]5246[/attach]
答案是7 但算出了是5
因為row3有2個條件
找出最少的數後 ,
條件1 只有1個最少的數 h1出最少的數的col
條件2 有2個or以上最少的數 出最左手邊的最少的數的col
所以 條件1+條件2= 只要出 最左手邊的最少的數的col 就ok.
作者:
Hsieh
時間:
2011-4-5 20:57
回復
5#
basarasy
Sub Ex()
Dim Ar(), Ay(), Rng As Range, A As Range, s%, j%
Set Rng = [A1:G1]
For Each A In Rng
If A = Application.Max(Rng) Then '如果是最大值
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address '記住位址
Ay(s) = A.Column '記住欄位
s = s + 1
End If
Next
For j = 0 To UBound(Ay) '最大值的下一格儲存格聯集
If Rng Is Nothing Then Set Rng = Cells(2, Ay(j)) Else Set Rng = Union(Rng, Cells(2, Ay(j)))
Next
For r = 2 To Cells(Rows.Count, 1).End(xlUp).Row '第2列以下迴圈
s = 0: Erase Ar
Set Rng = Nothing
For j = 0 To UBound(Ay)
If Rng Is Nothing Then Set Rng = Cells(r, Ay(j)) Else Set Rng = Union(Rng, Cells(r, Ay(j)))
Next
s = 0: Erase Ay: Erase Ar
For Each A In Rng
If A = Application.Min(Rng) Then '如果是最小值
ReDim Preserve Ar(s)
ReDim Preserve Ay(s)
Ar(s) = A.Address '記住位址
Ay(s) = A.Column '記住欄位
s = s + 1
End If
Next
Set Rng = Nothing
ck = Ay(0)
Next
[H1] = ck
End Sub
複製代碼
作者:
basarasy
時間:
2011-4-5 21:46
回復
6#
Hsieh
謝謝強大的Hsieh超級版主^^
真的很想學 如何把東西放入 集合 之後再放出來用><
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)