我有一种格式,当填充它并按下一个按钮时,它应该求和不同范围的单元格并替换它们。但是我不能让它工作。我认为它是参考。
Private Sub C2_Click()
Dim Partida As String
Dim Rng As Range, Pacas As Range, Kilos As Range, Devol As Range, Desp As Range
If Sheets("Reporte").Range("C4").Value <> "Blanco" Then
'------------------> Color
Partida = Worksheets("Reporte").Range("C3").Value
If Trim(Partida) <> "" Then
With Sheets("Color").Rows("6:6")
Set Rng = .Find(What:=Partida, After:=.Cells(.Cells.Count), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not Sheets("Reporte").Range("C5") Is Nothing Then
Set Pacas = Rng.Offset(16, 0)
Sheets("Color").Range(Pacas).Value = Sheets("Color").Range(Pacas).Value + Sheets("Reporte").Range("C5").Value
Else: GoTo K
End If
K:
If Not Sheets("Reporte").Range("C6") Is Nothing Then
Set Kilos = Rng.Offset(17, 0)
Sheets("Color").Range(Kilos).Value = Sheets("Color").Range(Pacas).Value + Sheets("Reporte").Range("C5").Value
Else: GoTo D
End If
D:
If Not Sheets("Reporte").Range("C7") Is Nothing Then
Set Devol = Rng.Offset(18, 0)
Sheets("Color").Range(Devol).Value = Sheets("Color").Range(Pacas).Value + Sheets("Reporte").Range("C5").Value
Else: GoTo De:
End If
De:
If Not Sheets("Reporte").Range("C8") Is Nothing Then
Set Desp = Rng.Offset(19, 0)
Sheets("Color").Range(Desp).Value = Sheets("Color").Range(Pacas).Value + Sheets("Reporte").Range("C5").Value
Else: GoTo C
End If
C:
End With
Else
PartidaN = MsgBox("Agregar partida", vbCritical, "Error")
End If
Else
'------------------> Blanco
End If
End Sub
总和行上的错误1004。