This formula uses the COUNTA function to count values in a range. COUNTA counts both numbers and text to so works well with mixed data.
The range B4:B8 contains 5 values, so COUNTA returns 5. The number 5 corresponds to the last row (last relative position) of data in the range B4:B100.
Note: This approach will fail if the range contains blank/empty cells. This formula based on the LOOKUP function can handle empty cells in the data.
You can use this formula to create a dynamic range with other functions like INDEX and OFFSET. See links below for examples and explanation: