我有一些代码可以从一个选项卡复制数据并将其粘贴到另一个选项卡中,然后翻转整个列上的数字符号。例如,原始选项卡中的-1变为1,而原始选项卡中的1变为-1。
出于某种原因,如果原始标签中的数字为负数,则不会变为正数。如果原始标签中的数字是正数,它将变为负数就好了。可能导致这种情况的任何想法?
最后3行代码是什么最终翻转了标志,但我粘贴了我的整个子,以防其他地方引起问题。提前谢谢!
Sub prep()
Dim c As Range
Dim IRow As Long, lastrow As Long
Dim rSource As Range
Dim wsI As Worksheet, wsO As Worksheet
Dim d As Range
Dim dSource As Range
Dim LR As Long
On Error GoTo Whoa
Set wsI = ThisWorkbook.Sheets("Ben")
Set wsO = ThisWorkbook.Sheets("Upload")
Application.ScreenUpdating = False
wsO.Range("P14", "AB10000").ClearContents
endrow = wsO.Cells(Rows.Count, "T").End(xlUp).Row + 1
With wsI
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Columns("O:R").Find(What:="*", _
After:=.Range("O1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
Set rSource = .Range("R1:R" & lastrow)
For Each c In rSource
Debug.Print c.Value
If IsNumeric(c.Value) Then
If c.Value > 0 Then
wsO.Cells(14 + IRow, 20).Resize(1, 4).Value = _
.Range("O" & c.Row & ":R" & c.Row).Value
wsO.Cells(14 + IRow, 25).Value = "XXXXXX" & .Range("J" & c.Row).Value
wsO.Cells(14 + IRow, 28).Value = .Range("N" & c.Row).Value
wsO.Cells(14 + IRow, 16).Value = "470"
wsO.Cells(14 + IRow, 17).Value = "I"
wsO.Cells(14 + IRow, 18).Value = "80"
wsO.Cells(14 + IRow, 19).Value = "A"
IRow = IRow + 1
End If
End If
Next
End With
For Each r In Range("W14", Range("W" & Rows.Count).End(xlUp))
r.Value = -r.Value
Next r