У меня возникли некоторые проблемы с получением значений из диаграммы, это захват неправильных значений, и если seats = 3 или 4, ничего не печатает. Я не получаю ошибки, когда код выполняется, и я изменяю значения столбцов, но работаю по кругу, пытаясь выяснить, почему он не вытягивает правильные значения.
Код проверяет значения из входных данных, показанных ниже (пример изображения входных данных), и запускает варианты выбора, чтобы определить, какому значению соответствуют входные данные для указанных c критериев, а затем выводит значение из заданного c ячейка на диаграмме.
Проблема, с которой я столкнулся сейчас, заключается в том, что значения печатаются неправильно, например:
Строка ввода данных 2 Eqp 767, Si 0400, Seat 2, Legs 2. Таким образом, если Seat = 2, тогда он проверяет количество ветвей, а затем проверяет, где значения Si попадают в диапазон времени 0400-0459.
If evalCell.Value = 2 Then
Select Case evalCell.Offset(0, 1).Value
Case 1
' Get the offset column in column F
chartColumn = b
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
Выход должен быть 1400, который находится в ячейке C6 на диаграмме, но он выдает 1600.
Данные диаграммы
Таблица C используется, если место 3 или 4. Затем разбивается на столбцы B & C - 777 и 767, D & E 330 и 787, а G & F не используются этим макросом.
Пример входных данных
Public Sub MonthCalc()
' Define objects
Dim sourceSheet As Worksheet
Dim chartSheet As Worksheet
Dim evalCell As Range
' Define other variables
Dim lastRow As Long
Dim chartColumn As Long
Dim chartRow As Long
Set sourceSheet = ThisWorkbook.Sheets("FLT Data")
Set chartSheet = ThisWorkbook.Sheets("FAR117Chart")
lastRow = sourceSheet.Range("E2").End(xlDown).Row
For Each evalCell In Range("E2:E" & lastRow).Cells
If evalCell.Value = 2 Then
Select Case evalCell.Offset(0, 1).Value
Case 1
' Get the offset column in column F
chartColumn = b
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 2
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 3
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 4
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 5
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 6
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
Case 7
' Get the offset column in column F
chartColumn = evalCell.Offset(0, 1).Value - 1
Select Case evalCell.Offset(0, -2).Value
' Column e = 2, c >= 0, c <= 359
Case 0 To 359
chartRow = 5
' Column e = 2, c >= 400, c <=459
Case 400 To 459
chartRow = 6
' Column e = 2, c >= 500, c <=559
Case 500 To 559
chartRow = 7
' Column e = 2, c >= 600, c <=659
Case 600 To 659
chartRow = 8
' Column e = 2, c >= 700, c <=1159
Case 700 To 1159
chartRow = 9
' Column e = 2, c >= 1200, c <=1259
Case 1200 To 1259
chartRow = 10
' Column e = 2, c >= 1300, c <=1659
Case 1300 To 1659
chartRow = 11
' Column e = 2, c >= 1700, c <=2159
Case 1700 To 2159
chartRow = 12
' Column e = 2, c >= 2200, c <=2259
Case 2200 To 2259
chartRow = 13
' Column e = 2, c >= 2300, c <=2359
Case 2300 To 2359
chartRow = 14
End Select
End Select
ElseIf evalCell.Value = 3 Then
' Column e = 3, b >= 330, b <=767
If evalCell.Offset(0, -3).Value >= 330 Or evalCell.Offset(0, -3).Value <= 767 Then
' Get the offset column in column D
chartColumn = 2
Select Case True
Case 0 To 559
chartRow = 18
Case 600 To 659
chartRow = 19
Case 700 To 1259
chartRow = 20
Case 1300 To 1659
chartRow = 21
Case 1700 To 2359
chartRow = 22
End Select
' Column e = 3, b >= 777, b <=787
ElseIf evalCell.Offset(0, -3).Value >= 777 Or evalCell.Offset(0, -3).Value <= 787 Then
' Get the offset column in column D
chartColumn = 0
Select Case True
Case 0 To 559
chartRow = 18
Case 600 To 659
chartRow = 19
Case 700 To 1259
chartRow = 20
Case 1300 To 1659
chartRow = 21
Case 1700 To 2359
chartRow = 22
End Select
End If
ElseIf evalCell.Value = 4 Then
' Add conditionals
' Column e = 3, b >= 330, b <=767
If evalCell.Offset(0, -3).Value >= 330 Or evalCell.Offset(0, -3).Value <= 767 Then
' Get the offset column in column D
chartColumn = 2
Select Case True
Case 0 To 559
chartRow = 18
Case 600 To 659
chartRow = 19
Case 700 To 1259
chartRow = 20
Case 1300 To 1659
chartRow = 21
Case 1700 To 2359
chartRow = 22
End Select
' Column e = 3, b >= 777, b <=787
ElseIf evalCell.Offset(0, -3).Value >= 777 Or evalCell.Offset(0, -3).Value <= 787 Then
' Get the offset column in column D
chartColumn = 0
Select Case True
Case 0 To 559
chartRow = 18
Case 600 To 659
chartRow = 19
Case 700 To 1259
chartRow = 20
Case 1300 To 1659
chartRow = 21
Case 1700 To 2359
chartRow = 22
End Select
End If
End If
'Cell G in the same line
evalCell.Offset(0, 2).Value = chartSheet.Range("B5").Offset(chartRow, chartColumn).Value
Next evalCell
End Sub