我想用下面的代码实现的是当range2大于range1×10或更多并且X没有出现在单元格G2中并且range1中的值不是该范围中的最低值时工作表上的某些值被添加到不同工作簿上的不同工作表。我还需要代码在大约100个工作表上执行此操作,这些工作表在同一工作簿中同时打开。它的日志数据正在从第三方输入到工作表中,但只有在满足正确的标准时才会记录它。
除了在满足数据记录条件之后我必须点击range2中的单元格以便获得excel以实现满足标准之外,它完美地工作。我需要它在任何工作表上进行更改后立即执行操作并记录该工作表中的数据。它还需要继续使用所有其他工作表
Worksheet SelectionChange
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim rng2 As Range
Dim dblMin As Double
Dim val, val1, val2, val3, val4, val5 As Variant
Set rng = Range("ag9:ag100")
Set rng2 = Range("ah9:ah100")
dblMin = Application.WorksheetFunction.Min(rng2)
If Not Intersect(Target, Range("ah9:ah100")) Is Nothing Then
If Range("G2").Value = "X" Then
End
Else
For Each cell In rng
If cell.Value >= cell.Offset(0, -1).Value + 10 And Range("c2") > 4000 And cell.Offset(0, 1).Value <> dblMin Then
Range("G2").Value = "X"
val1 = Range("c2").Value
val2 = Range("c4").Value
val3 = cell.Offset(0, 2).Value
val4 = cell.Offset(0, 1).Value
val5 = Range("f4").Value
val6 = cell.Offset(0, -1).Value
val7 = cell.Value
Workbooks.Open Filename:="C:\Desktop\Log.xlsx"
ActiveWorkbook.ActiveSheet.Range("c2" & Rows.Count).End(xlUp).Offset(1).Value = val1
ActiveWorkbook.ActiveSheet.Range("d2" & Rows.Count).End(xlUp).Offset(1).Value = val2
ActiveWorkbook.ActiveSheet.Range("e2" & Rows.Count).End(xlUp).Offset(1).Value = val3
ActiveWorkbook.ActiveSheet.Range("f2" & Rows.Count).End(xlUp).Offset(1).Value = val4
ActiveWorkbook.ActiveSheet.Range("g2" & Rows.Count).End(xlUp).Offset(1).Value = val5
ActiveWorkbook.ActiveSheet.Range("h2" & Rows.Count).End(xlUp).Offset(1).Value = val6
ActiveWorkbook.ActiveSheet.Range("i2" & Rows.Count).End(xlUp).Offset(1).Value = val7
Exit For
End If
Next
End If
End If
End Sub