Я пытался получить значение из рабочего листа, чем текущее. Это то, что я имею до сих пор:
'Variables at the top of the code
Dim workBookThis As Workbook 'This Workbook
'Dim WBN As Workbook 'New workbook
Dim activeSheet As Worksheet 'Data
Dim hourSheet As Worksheet 'Lookup sheet
'Dim WSR As Worksheet 'Report worksheet, in WBN
Set workBookThis = Workbooks("SQE Workload Estimates Test Copy.xlsm")
Set activeSheet = workBookThis.Worksheets(sheetName)
Set hourSheet = workBookThis.Worksheets("Hours Breakdown")
---------------------------------------------------------------------------------------------------------
'Part of the code not functioning properly.
Dim hours As Integer
'hours = 120
'Dim hourSheet As Worksheet
'Set hourSheet = ThisWorkbook.Sheets("Hours Breakdown")
Dim combinedIndividual As Integer
'Start of for loop which will run from csIndividual up to 20.
For combinedIndividual = 0 To 20
On Error Resume Next
'Start of if statement which says if the cell's value three cells to the left and up until it hits a non-blank cell of the Target cell is equal to ESQ.
If Cells(rowPos - combinedIndividual, colPos - 2).Value = "Combined System" And _
Cells(rowPos - combinedIndividual, colPos - 1).Value = "ESQ" Then
hours = ThisWorkbook.Sheets("Hours Breakdown").Range(Cells(135, 2)).Value
'hours = 12
'MsgBox "Combined System, ESQ"
Exit For
ElseIf Cells(rowPos - combinedIndividual, colPos - 2).Value = "Combined System" And _
Cells(rowPos - combinedIndividual, colPos - 1).Value = "Legacy" Then
'hours = ThisWorkbook.Sheets("Hours Breakdown").Range(Cells(136, 2)).Value
hours = 16
'MsgBox "Combined System, Legacy"
Exit For
End If
'Start of if statement which says if the cell's value three cells to the left and up until it hits a non-blank cell of the Target cell is equal to ESQ.
If Cells(rowPos - combinedIndividual, colPos - 2).Value = "Individual" And _
Cells(rowPos - combinedIndividual, colPos - 1).Value = "ESQ" Then
'hours = ThisWorkbook.Sheets("Hours Breakdown").Range(Cells(136, 2)).Value
hours = 20
'MsgBox "Individual, ESQ"
Exit For
ElseIf Cells(rowPos - combinedIndividual, colPos - 2).Value = "Individual" And _
Cells(rowPos - combinedIndividual, colPos - 1).Value = "Legacy" Then
'hours = ThisWorkbook.Sheets("Hours Breakdown").Range(Cells(136, 2)).Value
hours = 24
'MsgBox "Individual, Legacy"
Exit For
End If
Next combinedIndividual
MsgBox hours
Мне нужно иметь возможность изменять значение часов на основе критериев в операторах If. К сожалению, каждая попытка приводила к 0. Я, кажется, объявил рабочую книгу и листы как свои собственные переменные, и я использую код, который работал в других ситуациях. Возможно, он не самый красивый, но он функционирует.
Если кто-то может заметить явную ошибку или если мой подход каким-то образом неверен, поделитесь со мной. Спасибо.