A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
The final solution to this is provided below. The basic issue was to identify specific cells that changed on a series of worksheets in the workbook in response to changes in cells on one other worksheet. The number of the "other" sheets is variable and can change over time. The specific layout of those can change in terms of number of columns/rows used, but each follows the same general layout. The code was all placed in the code module for the one sheet where the changes are initiated (by changing a value in row 8 on that sheet)
Option Explicit
'these constant values 'define' the different sheets so that
'the code can determine where the values on Start are that
'need to be monitored and
'how things are laid out on the "t_#" type sheets,
'and how to determine that it is a "t_#" type sheet
'in case other sheets besides the 'Start' and "t_#" type sheets
'are in the workbook
' this is the row on the Start sheet where the values we
' need to monitor are located. These MUST be the only
' entries on that row of that sheet!
Const startDataRow = 8
'these refer to the "t_#" type sheets
' where to find the "POD ix of X" type entries
Const sheetKeyPhraseCell = "B3"
' enough of the "POD ix of X" type entries to
' ensure accurate identification of cell B3
' You must start at the left side of whatever phrase is
' being used and include enough characters to uniquely
' identify it.
Const sheetKeyPhraseText = "POD " ' 1st 4 characters are always "POD "
'this will be the number of columns between the
'columns with 'B4', C6, D11, E7, etc type entries in them
'Example: 1st is C, next is F, so 6-3 = 3
Const columnGap = 3
'these variables are set up in the
' Worksheet_Change() event process as needed to
' define any given sheet that must be processed
'
'this will be the sheet to be processed
Dim anyPODSheet As Worksheet
'this will be the first row to examine for
'entries like B4, C6, D11, E7, etc.
'the last row will be determined at run time
'by examining the entries in column A of
'the sheet itself, allowing for any given
'sheet to have a different number of entries (used rows)
'or to all be the same, but user doesn't have to track it.
Dim firstPODRow As Long
'This will be the letter ID of the first column on the
'sheet with a 'B4', C6, D11, E7, etc type entry in it
Dim firstColID As String
'this will be the letter ID of the last column on the
'sheet with a 'B4', C6, D11, E7, etc type entry in it
Dim lastColID As String
'this holds the value of 'Target' from the Start Worksheet_Change() event
Dim theTargetValue
Private Sub Worksheet_Change(ByVal Target As Range)
'calls Sub ProcessOneSheet() below
'once for each sheet that needs to be processed
'prior to the call the variables declared above
'are set up for the specific sheet.
'
'did did (all of) the change(s) take place in the proper row?
If Target.Row <> startDataRow Then
Exit Sub
End If
'and did just one of them change?
If Target.Cells.Count > 1 Then
Exit Sub
End If
'was the value simply deleted with [Del] key?
If IsEmpty(Target) Then
Exit Sub
End If
'save the value of Target for comparison at the sheet
'level so we only update rows where it matches properly
theTargetValue = Target.Value
'work through all worksheets in the workbook, identifying those
'that have the key phrase text ("POD ") in the key phrase cell (B3)
For Each anyPODSheet In ThisWorkbook.Worksheets
'this phrase must start at the left-most part of the entry
If InStr(UCase(Trim(anyPODSheet.Range(sheetKeyPhraseCell))), UCase(Trim(sheetKeyPhraseText))) = 1 Then
'it appears to be a "t_#" type of sheet
firstPODRow = Range(sheetKeyPhraseCell).Row + 1
'assumes that the key phrase cell is directly above the first
'entry in the 3-column groups of data
'so add 1 to that column number to get the first column # for the "B4", "D16" type entries
firstColID = Left(Range(sheetKeyPhraseCell).Offset(0, 1).Address(True, True), _
InStr(2, Range(sheetKeyPhraseCell).Offset(0, 1).Address(True, True), "$") - 1)
lastColID = anyPODSheet.Cells(firstPODRow, Columns.Count).End(xlToLeft).Address(True, True)
lastColID = Left(lastColID, InStr(2, lastColID, "$") - 1)
Call ProcessOneSheet
End If
Next ' end anyPODSheet loop
End Sub
Private Sub ProcessOneSheet()
'this will process a sheet to update counts
'based on values of the Public constants defined
'above as set up by the calling routine
'the sheets must be unprotected for this to
'function properly, each could be unprotected/protected
'within this module if required.
'
'Define local working variables
Dim colPtr As Integer
Dim lastPODRow As Long
Dim rowPtr As Long
'make sure that at least the worksheet has been defined
If anyPODSheet Is Nothing Then
Exit Sub ' do nothing, don't know what sheet to work with
End If
With anyPODSheet
lastPODRow = .Range("A" & Rows.Count).End(xlUp).Row
For colPtr = Range(firstColID & 1).Column _
To Range(lastColID & 1).Column Step columnGap
For rowPtr = firstPODRow To lastPODRow
'modified to also test if the numeric value for this 3-cell
'group matches the value that was entered on the Start sheet
'only updates counts if it does
If Len(Trim(.Cells(rowPtr, colPtr))) > 0 _
And .Cells(rowPtr, colPtr).Offset(0, -1) = theTargetValue Then
.Cells(rowPtr, colPtr).Offset(0, 1) = _
.Cells(rowPtr, colPtr).Offset(0, 1) + 1
End If
Next ' end rowPtr loop
Next ' end colPtr loop
End With ' end of anyPODSheet processing
'release resource back to the system
Set anyPODSheet = Nothing
End Sub