我写了一个宏,虽然它可以工作,但在功能上它不是需要的。这是一个交互式清单,可以分解机器的多个区域,如果它们正在工作,请检查它们,然后更新包含多个部分的主列表。但是,它一次只能处理一个单元格,并且需要能够一次处理多个单元格(包括行和列)。这是我当前的代码:
'Updates needed:
' Make so more than one cell works at a time
' in both x and y directions
Private Sub Worksheet_Change(ByVal Target As Excel.range)
Dim wb As Workbook
Dim mWS As Worksheet
Dim conName As String
Dim mCol As range
Dim mCon As Integer
Dim count As Long
Dim cell As range
Dim y As String
count = 1
y = ""
Set wb = ActiveWorkbook
Set mWS = wb.Sheets("Master")
Set mCol = mWS.range("B:B")
mCon = 0
'Selects the name of the string value in which we need to search for in master list
If Target.Column < 100 Then
ThisRow = Target.Row
conName = ActiveSheet.Cells(ThisRow, "B")
y = Target.Value
End If
'search for matching string value in master list
For Each cell In mCol
If cell.Value = conName Then
mCon = count
Exit For
End If
count = count + 1
Next
'mark as "x" in Master list
Dim cVal As Variant
Set cVal = mWS.Cells(count, Target.Column)
cVal.Value = y
End Sub
发生了什么 - 如果我为多行或多列向下拖动“x”,我的代码会在 y = Target.Value 处中断,并且只会更新我首先选择的单元格及其在主列表中的对应项。它应该做的是,如果我将“x”拖放到多行列上,它应该更新我正在处理的工作表和主列表中的所有列。我一次只为一个单元格设置宏,我不知道如何设置它以拖放多行的“x”值