Option Explicit
Sub TESTsearch()
Dim i As Integer
For i = 3 To 14
Select Case Cells(i, 2)
Case "A"
Cells(i, 3) = 1
Case "B"
Cells(i, 4) = 1
Case "C"
Cells(i, 5) = 1
Case "D1"
Cells(i, 6) = 1
Case "D2"
Cells(i, 7) = 1
Case "D3"
Cells(i, 8) = 1
Case "D4"
Cells(i, 9) = 1
Case "D5"
Cells(i, 10) = 1
Case "D6"
Cells(i, 11) = 1
Case "D7"
Cells(i, 12) = 1
Case "D8"
Cells(i, 13) = 1
Case "D9"
Cells(i, 14) = 1
Case "D10"
Cells(i, 15) = 1
End Select
Next i
End Sub作者: kasa 時間: 2015-12-23 22:09
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
If Not Intersect(Target, Range("B3:B14")) Is Nothing Then
For i = 3 To 14
Select Case Cells(i, 2)
Case "A"
Cells(i, 3) = 1
Case "B"
Cells(i, 4) = 1
Case "C"
Cells(i, 5) = 1
Case "D1"
Cells(i, 6) = 1
Case "D2"
Cells(i, 7) = 1
Case "D3"
Cells(i, 8) = 1
Case "D4"
Cells(i, 9) = 1
Case "D5"
Cells(i, 10) = 1
Case "D6"
Cells(i, 11) = 1
Case "D7"
Cells(i, 12) = 1
Case "D8"
Cells(i, 13) = 1
Case "D9"
Cells(i, 14) = 1
Case "D10"
Cells(i, 15) = 1
End Select
Next i
End If
End Sub作者: URCHEN 時間: 2015-12-24 06:12
Option Explicit
Private Sub CommandButton1_Click()
Dim SH1W As Worksheet
Dim Ra1 As Range
Dim X, Y
Set SH1W = Sheets("工作表1")
Set Ra1 = SH1W.Range("B2:B" & [B65536].End(xlUp).Row)
X = Ra1.Offset(1, 0).Resize(1, 1).Value
SH1W.Range("C3:O14").ClearContents
For Each X In Range("B3:B14")
For Each Y In Range("C2:O2")
If X = Y Then
Y.Offset(X.Row - 2, Y.Row - 2).Resize(1, 1).Select
Selection = "1"
End If
Next Y
Next X
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xR As Range, M
With Target
If .Column <> 2 Or .Columns.Count > 1 Then Exit Sub '非第2欄,或選取兩欄以上,跳出
On Error GoTo 999 '發生錯誤時,執行標記999那行程式
Application.EnableEvents = False '關閉事件觸發
For Each xR In .Cells '歷遍選取區全部儲存格(可使用貼上多個)
If xR.Row > 2 Then
xR(1, 2).Resize(1, 99).ClearContents '清除右方原有資料
M = Application.Match(xR, [2:2], 0) '找出Item在第2列的位置
If IsNumeric(M) Then xR(1, M - 1) = 1 '若有符合,填入1
End If
Next
End With
999: Application.EnableEvents = True '恢復事件觸發
End Sub作者: yen956 時間: 2015-12-24 15:43
試試看:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MH, RngB As Range, Rng2 As Range
Set RngB = [B3:B65536] '輸入區
Set Rng2 = [C2:O2] '比對區
If Target.Count > 1 Then Exit Sub '如果兩格以上同時Change,跳出
If Not Intersect(Target, RngB) Is Nothing Then '如果 Target 與 比對區 有交集