Solved Understanding Code (1 Viewer)

GC2010

Registered User.
Local time
Today, 10:54
Joined
Jun 3, 2019
Messages
120
I am taking over a project that someone else created and I want to understand what the code is doing. This line of code, is it simply finding the last column with data?
Code:
Dim dColumn As Long
dColumn= Excel.Cells(1, Excel.Columns.Count).End(Excel.xlToLeft).Column
 

plog

Banishment Pending
Local time
Today, 12:54
Joined
May 11, 2011
Messages
11,646
Not to be pedantic, but its getting the number of the last column with data, and not a reference of the column itself.

If it was getting a reference to the column itself you could use it to do things to the column, for example:

dColumn.Interior.Color = vbBlue

To do that with what you have you would have to do this:

Columns(dColumn).Interior.Color = vbBlue
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:54
Joined
May 7, 2009
Messages
19,242
Excel.Cells(1, Excel.Columns.Count), selects the Last Column, on Row 1
End(Excel.xlToLeft).Column, find non-blank cell on that row (1st row), starting from the Last Column going to the First Column (right to left).

if it finds, non-blank cell, it assign it to dColumn variable.
if there is non-blank cell found, it returns the First Column (1).
 

Users who are viewing this thread

Top Bottom