Fig 1
So similar to “Fig 1” above you would like to reference row 14 of the table and possibly iterate over each of the cells.
The YouTube video below will take you through the details of how to reference the last row with a vba range object, I will summarise how to do this here, and you can download the Excel vba macro spreadsheet that goes with the tutorial below.
The basics of the solutions are coded below
Line 5 gets a reference to all the data in Fig 1 above.
Line 8 creates a new variable that references the header in spreadsheet row 3
Get the spreadsheet used in the tutorial above.
Also receive updates on when new blog or video tutorials are released.
01 Sub FormatLastRow() 02 Dim rngHeader As Range, rngdata As Range, rngLastRow As Range 03 04 ' Substitute the actual worksheet name for "Register" 05 Set rngData = ThisWorkBook.Worksheets("REGISTER").Range("A4").CurrentRegion 06 07 ' Line above gets reference to all of the data 08 Set rngHeader = rngData.Resize(1) ' Get reference to header row. 09 10 ' Offset the header reference by the number of rows in the data, less one row to get reference to last row. 11 Set rngLastRow = rngData.Resize(1).Offset(rngData.Rows.Count - 1) 10 For Each rngCell In rngLastRow 11 ' rngCell iterates over each cell in this last row, 12 ' substitute your own code for line 14 or download 13 ' spreadsheet with code to get other ideas. 14 rngCell.select 15 Next 16 17 ' Clean up object variables 18 Set rngData = Nothing: Set ringleader = Nothing: Set rngLastRow = Nothing 19 End Sub
If you found this article really helpful, then consider grabbing me a coffee, it takes a lot of work and expense to keep this site going, the more caffeine I have the harder I can work.
And if you do grab me a coffee, thanks for your support 😉
Neelesh says
Hi Sean,
I liked u r approach while writing VBA codes u approach is unique and prevents unnecessary coding.
I having been writing VBA codes since last 7 years and visited many sites and viewed many vedios on YouTube but I think your method is the best.
Thank you,
Neelesh