OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 876
- Office Version
- 365
- Platform
- Windows
Team Mr. Excel
I am trying to locate the last occupied column. I thought that I knew how to do it. But I cannot figure this simple task out.
I have a one-celled range name for the upperleftmost cell in the data range (cell O4). In code a VBA range object named rTargetCell that points to that cell. Data has 12 columns. There is nothing to the the right of the data.
Incidentally I have nine columns of user data in columns A through I.
So, I am hoping for code to return the number 26 as the last column. (Column Z is the last one with data.) But Debug.Print reports column 9.
I appreciate your assistance!
Jim
I am trying to locate the last occupied column. I thought that I knew how to do it. But I cannot figure this simple task out.
I have a one-celled range name for the upperleftmost cell in the data range (cell O4). In code a VBA range object named rTargetCell that points to that cell. Data has 12 columns. There is nothing to the the right of the data.
Incidentally I have nine columns of user data in columns A through I.
VBA Code:
Dim rTargetCell As Range
Dim iLastColumn As Long
Set rTargetCell = [ContactsData].Range("Header_FirstNameData")
iLastColumn = rTargetCell.End(xlToLeft).Column
Debug.Print "iLastColumn = " & iLastColumn
So, I am hoping for code to return the number 26 as the last column. (Column Z is the last one with data.) But Debug.Print reports column 9.
I appreciate your assistance!
Jim