|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 missyoua 于 2024-9-15 06:10 编辑
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Worksheet.Name = "Sheet2" And Target.Column = 1 And Target.Row >= 3 And Target.Row <= 127 Then
Dim searchValue As Variant
searchValue = Target.value
Dim sheet1 As Worksheet
Set sheet1 = ThisWorkbook.Sheets("Sheet1")
Dim foundRow As Long
foundRow = 0
Dim i As Long
For i = 3 To 127
If sheet1.Cells(i, 1).value = searchValue Then
foundRow = i
Exit For
End If
Next i
If foundRow > 0 Then
Dim sourceRange As Range
Set sourceRange = sheet1.Rows(foundRow)
Dim destinationRange As Range
Set destinationRange = Target.EntireRow
Dim j As Long
For j = 1 To sourceRange.Columns.Count
Dim value As Variant
value = sourceRange.Cells(1, j).value
If IsNumeric(value) Then
If value = 0 Then
destinationRange.Cells(1, j).value = ""
Else
destinationRange.Cells(1, j).value = Val(value)
End If
Else
destinationRange.Cells(1, j).value = value
End If
Next j
End If
End If
End Sub
请教一下大家为什么我使用这个VBA 会卡顿几秒呢 怎么才不卡
|
|