I’m reading the last row in a sheet called “GANT”, but this function is actually called within worksheet_change event of a DIFFERENT sheet- Sheet2.
The cose is counting the last row in Sheet2 and not GANT. Please see the code below.
-----------------
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("GANT").Select
'///Find the last row with any data and call it mRow
Dim lRow As Long, lCol As Integer, mRow As Long, mCol As Integer
lCol = ActiveSheet.UsedRange.Columns.Count
mRow = 0
For i = 1 To lCol
lRow = Range(Cells(Rows.Count, i), Cells(Rows.Count, i)).End(xlUp).Row
If lRow > mRow Then
mRow = lRow
mCol = i
Else
End If
Next i
lastcell = Range(Cells(mRow, mCol), Cells(mRow, mCol)).Address
maxrow = mRow
If Target.Row < 51 And Target.Column < 3 Then
Dim oCell As Range
t = 1
For Each oCell In Target
namechanged = Sheets("Colour Coding").Cells(Target.Row, 1)
For p = 1 To mRow
.....
.....
Next oCell
End If
End Sub