返回列表 上一主題 發帖

有條件取代儲存格內容

有條件取代儲存格內容

取代.rar (34.07 KB) 請問可否解決這問題

本帖最後由 GBKEE 於 2011-7-6 10:15 編輯

回復 15# mmggmm
更正是 As Variant 不是  As Variantr  是我不太用心!!  
PS:感謝 oobird 版主指正

TOP

GBKEE :
   請問As Variantr 和 As Variant 有何分別因為改為 As Variant 就ok了

TOP

回復 13# mmggmm
Dim Ay(1), Y As Integer, A As Range
Y為數字型態是Integer
Y不為數字則傳回 錯誤值 "#NA"
固須改為   As Variantr 沒被明確宣告為其他型態

TOP

no1.JPG

GBKEE :執行後現以上情況

TOP

回復 11# mmggmm
  1. Sub Ex()
  2.     Dim Ay(1), Y As Integer, A As Range
  3.     With Sheets("POSIT")
  4.         Ay(0) = Application.Transpose(.Range("P2:P" & .Range("P" & Rows.Count).End(xlUp).Row))
  5.         Ay(1) = Application.Transpose(.Range("Q2:Q" & .Range("O" & Rows.Count).End(xlUp).Row))
  6.     End With
  7.     For Each A In ActiveSheet.[H3:AL400]
  8.         If A <> "" Then
  9.             Y = Application.Match(A, Ay(0), 0)
  10.             If IsError(Y) Then
  11.                 A.Value = "X"
  12.             ElseIf Y > 0 Then
  13.                 If (Y <= 14 Or Y >= 24) And Cells(A.Row, "G") = Ay(1)(Y) Then A.Value = "X"
  14.             End If
  15.         End If
  16.     Next
  17. End Sub
複製代碼

TOP

GBKEE :
謝謝,請問H3:AL400內如是空格亦保留,請問如何?

TOP

回復 9# mmggmm
依據 7樓附檔修改的
  1. Sub Ex()
  2.     Dim Ay(1), Y
  3.     With Sheets("POSIT")
  4.         Ay(0) = Application.Transpose(.Range("P2:P" & .Range("P" & Rows.Count).End(xlUp).Row))
  5.         Ay(1) = Application.Transpose(.Range("Q2:Q" & .Range("O" & Rows.Count).End(xlUp).Row))
  6.     End With
  7.     For Each A In ActiveSheet.[H3:AL400]
  8.         Y = Application.Match(A, Ay(0), 0)
  9.         If IsError(Y) Then
  10.             A.Value = "X"
  11.         ElseIf Y > 0 Then
  12.             If (Y <= 14 Or Y >= 24) And Cells(A.Row, "G") = Ay(1)(Y) Then A.Value = "X"
  13.         End If
  14.     Next
  15. End Sub
複製代碼

TOP

GBKEE:
P欄資料不會重復,P15:Q15可以刪除,因為先前是有資料的.謝謝

TOP

本帖最後由 GBKEE 於 2011-7-3 11:26 編輯

回復 7# mmggmm
此區(P16:Q24)在執行巨集後必定保留
不管sheet"Meals"G:G是屬"YES" "NO" 都保留嗎?

Q2:Q14 是NO     ->sheet"Meals"G:G是屬"YES"必定保留
Q25:Q36 是YES  ->sheet"Meals"G:G是屬"NO"必定保留
請問POSIT 的P欄所有資料會重復嗎?
P15:Q15為何是空白的

TOP

        靜思自在 : 人生不一定球球是好球,但是有歷練的強打者,隨時都可以揮棒。
返回列表 上一主題