我正在尝试匹配具有相同记录的工作表,并根据另一个工作表更新一个工作表。更新与'1'更新在各自的细胞中。
能够写入,因此具有值的单元格将分别更新。 问题是我无法弄清楚如何增加包含字符串的单元格。 (某些单元格包含"> 1","> 2"依此类推)我正在尝试增加那些,如果需要更改为"> 2"和"> 3"等等。
我应该粘贴代码的那一刻是粗体。
Sub Increment()
For Each SnowCell In MySnowRange
For Each TrakerCell In MyTrakerRange
If TrakerCell.Value = SnowCell.Value Then
If TrakerCell.Offset(, 1).Value <> SnowCell.Offset(, 1).Value Then
TrakerCell.Offset(, 1).Value = SnowCell.Offset(, 1).Value
Select Case SnowCell.Offset(, 1).Value
Case "In Queue"
If Application.WorksheetFunction.IsNumber(TrakerCell.Offset(, 3).Value + 1) = True Then
TrakerCell.Offset(, 3).Value = TrakerCell.Offset(, 3).Value + 1
Else
**TrakerCell.Offset(, 3).Value = Split(TrakerCell.Offset(, 3).Value)**
Case "Assigned"
TrakerCell.Offset(, 4).Value = TrakerCell.Offset(, 4).Value + 1
Case "Work In Progress"
TrakerCell.Offset(, 5).Value = TrakerCell.Offset(, 5).Value + 1
Case "Pending"
TrakerCell.Offset(, 6).Value = TrakerCell.Offset(, 6).Value + 1
Case "Resolved"
TrakerCell.Offset(, 7).Value = "Resolved"
End Select
ElseIf TrakerCell.Offset(, 1).Value = SnowCell.Offset(, 1).Value Then
Select Case SnowCell.Offset(, 1).Value
Case "In Queue"
TrakerCell.Offset(, 3).Value = TrakerCell.Offset(, 3).Value + 1
Case "Assigned"
TrakerCell.Offset(, 4).Value = TrakerCell.Offset(, 4).Value + 1
Case "Work In Progress"
TrakerCell.Offset(, 5).Value = TrakerCell.Offset(, 5).Value + 1
Case "Pending"
TrakerCell.Offset(, 6).Value = TrakerCell.Offset(, 6).Value + 1
Case "Resolved"
TrakerCell.Offset(, 7).Value = "Resolved"
End Select
End If
Else
End If
Next
Next
End Sub
答案 0 :(得分:0)
从我看到的情况来看,您的比较正在发挥作用,这是您需要解决的更新。编写一个函数,它将返回更新的值。你需要做的功能是首先从字符串中提取数值(看看这两篇文章如何做到这一点:Post1和Post2)。现在您已拥有数值,请根据您的要求增加它。接下来,将数值替换为新的更新值(这应该太难了:您拥有旧值和新值,只需使用Replace
在字符串中更改它)。您现在可以使用此功能将值分配给Offset
单元格
答案 1 :(得分:0)
谢谢!
这样做是有效的:
Case "In Queue"
If Application.WorksheetFunction.IsNonText(TrakerCell.Offset(, 3).Value) = True Then
TrakerCell.Offset(, 3).Value = TrakerCell.Offset(, 3).Value + 1
Else
a = Left(TrakerCell.Offset(, 3).Value, 1)
b = Right(TrakerCell.Offset(, 3).Value, Len(TrakerCell.Offset(, 3).Value) - 1)
c = b + 1
d = a & c
TrakerCell.Offset(, 3).Value = d
End If
:!)
答案 2 :(得分:0)
如果您知道数字前面始终只有一个字符,那么只需:
Set c = TrakerCell(, 4) ' same as TrakerCell.Offset(, 3).Resize(1, 1)
c.Value = Left(c, 1) & (Mid(c, 2) + 1)
但如果非数字字符的数量不同,则可以将其更改为:
Set c = TrakerCell(, 4)
L = Len(c) - Len(Str(Val(StrReverse(c)))) + 1 ' number of characters before the number + 1
c.Value = Left(c, L) & (Mid(c, L + 1) + 1)