Я пытаюсь найти несоответствие переменных в этом коде для моего кода VBA моих коллег. Тем не менее, я не смог найти проблему. Код должен обновлять 2 разных листа на основе ручного ввода на третьем листе. Это связано с опасностями безопасности.
Отладчик говорит, что эта строка кода испортила
Previouscellcontentbefore = ActiveCell.Offset(rowbefore + 1, columbefore + 1)
Полный код:
Dim I As Integer
Dim row As Integer
Dim before As String
Dim after As String
Dim cons As String
Dim conscat As String
Dim checks As String
Dim check2 As String
Dim check3 As String
Dim rowbefore As String
Dim columbefore As String
Dim rowafter As String
Dim columafter As String
Dim checkbefore As String
Dim checkafter As String
Dim Previouscellcontentbefore As Integer
Dim Previouscellcontentafter As Integer
Sheets("for calculations").Visible = True
cons = Application.InputBox(prompt:="Personnel; Environment; Assets; Reputation; All", Title:="Choose consequence (NB: Case sensitive)", Default:="All")
Worksheets("For calculations").Activate
Range("D37:I42").ClearContents
Range("L37:Q42").ClearContents
Range("C34").ClearContents
Select Case cons
Case "All"
Range("C34").Value = "Risk matrix shows all types of consequences"
Case "Personnel"
Range("C34").Value = "Risk matrix shows all types of Personnel consequences"
Case "Environment"
Range("C34").Value = "Risk matrix shows Environmental consequences"
Case "Asset"
Range("C34").Value = "Risk matrix shows Asset consequences"
Case "Reputation"
Range("C34").Value = "Risk matrix shows Reputation consequences"
End Select
For I = 1 To 200
Range("C47").Value = Worksheets("HAZIDS").Cells(I + 5, 2).Value
conscat = Range("F47")
check2 = cons Like conscat
check3 = cons Like "All"
If cons Like "All" Then
check2 = True
End If
If check2 Then
before = Range("D47")
after = Range("E47")
rowbefore = Mid(before, 2, 1)
columbefore = Mid(before, 4, 1)
rowafter = Mid(after, 2, 1)
columafter = Mid(after, 4, 1)
checkbefore = Not rowbefore Like "" And Not columbefore Like ""
checkafter = Not rowafter Like "" And Not columafter Like ""
If checkbefore Then
Range("C36").Select
Previouscellcontentbefore = ActiveCell.Offset(CInt(rowbefore) + 1, CInt(columbefore) + 1)
ActiveCell.Offset(CInt(rowbefore) + 1, CInt(columbefore) + 1) = Range("C47").Value & ", " & Previouscellcontentbefore
If checkafter Then
Range("K36").Select
Previouscellcontentafter = ActiveCell.Offset(CInt(rowafter) + 1, CInt(columafter) + 1)
ActiveCell.Offset(CInt(rowafter) + 1, CInt(columafter) + 1) = Range("C47").Value & ", " & Previouscellcontentafter
End If
End If
End If
End Sub
Я ожидаю, что макрос обновит лист "Матрица рискадо "и" матрица риска после ", основанная на ручном вводе в" HAZIDS ". Тем не менее, лист" Для расчетов ", кажется, глючит