alright so in this video I'm gonna take all the code we wrote to get the last row and I'm gonna
convert it to last column instead of being last row so how do we find the last column in our data
instead of finding the last row and I'm not gonna go in detail about these lines and what they mean
if you want to understand that you should watch the first video before this one the one where
I show how to find the last row but in this one I'm just gonna go to this this data I guess and
we'll get started so the first method we'll do control right to get to the right end of this
data and that would be I'm just gonna change this to control right and then I'll say LC now
instead of LR comment this line for last row so to find the last column we're gonna go to a one
cell first which is that left corner here and from that we're gonna do Excel to right so be careful
is not Excel right it's Excel too right and this time we're gonna get the column not the row so
now if I run this code see we get six that's one two three four five six that's our first
method let's move to the next one last column for this one instead of doing control right from Avon
cell we're gonna go to the last column and do control left to get to the first column with
some data in it so again that's gonna be in the first row and we're gonna go in the first row
the last column in our spreadsheet so we'll just do cells and we need to be in the first row and
the last column will do columns that count to get the last column in the spreadsheet and then we'll
do Excel to left instead of Excel to right and then instead of dot row will get dot column to
get the column number so again if I run this code it should give us six and again I'm not gonna talk
about advantages or disadvantages if you want to understand those watch the first video four rows
the next one is finding using that find method to find the last column that is gonna be this
last column so we're gonna do find and the only thing we really need to change here is instead
of doing search by rows I guess if we do excel by columns and search by columns and get the
column number so that should get us to what we need so now if we are going by columns like this
right we're gonna go this way with our search instead of by rows where we go like this way if
we go by columns and we start in the cell but then we do previous that means we're gonna go
from the other end and we're gonna go from like this columns and search search search search
until we find the first column with some data in it then we're gonna hit that and we're gonna get
the last column so if you want to find the last column and there is no row you can trust this
should be a good method to go about this let's just run this see we get six again now if I go
to this one which is a little more Messier here let's say I don't have this category here too
if we run this see we get five so that should get us this which is one two three four five so
that's that now again this is the same thing with numbers instead of these so this is the same this
is the same this part that says excel by columns so that would be not this one not this one which
is the partial here it would be this one and I guess should be the second one if I'm not mistaken
and the rest should be the same with exception that row will change to column so let's just run
this and make sure we get what we should looks good so this is the same as this one only with
numbers replaced instead of this enumeration right here now let's get to the region if we
do that whole control a thing the last column based on this we can do this go from a one cell
do control a and then instead of rows that count will do columns that count to figure out how many
columns we have and if we run this let me just click on some random cell here first that gives
us five that's the number of columns we have in the selection now let's say your data is more like
this and you need to find the last column in this case which should be G so we first have to get to
dis and then get the last column so how do we do that so first let's get the number of blank
columns on left so I'm just gonna call it L C so this message box prints it out so again the
way we can do that we can go to this a 2 cell which is the second row first column 2 1 and
then instead of going ctrl down we can do Excel to write and that's gonna do control right and
then current region is gonna basically we're gonna go here control right control a select
all of this and with that we're gonna find the column number which is the first column with
some data in it and then minus 1 would be the number of blank rows so this should return to
because well that's two blank rows if I do this that should give me three and if I delete all
of those and then we do this zero that's good the number of blank rows gonna get rid of this
part and I'm gonna add those blank rows back so now we're just gonna convert this row line
we did before to a column so the last column if we use this method again we're gonna start
from the second row first column we're gonna do control right which is Excel to write and
then we're gonna select the current region we're gonna get the column and then minus one because we
want the number of blank columns so this will be the number of blank columns plus we again
will take second row and first do control right current region and then instead of doing rows
that count will do columns that count to count the number of columns so now if we just run let
me make this bigger a little bit still doesn't fit I'm gonna just move this to the next line
here we go so again underscore if you remember I've mentioned this already that's a way for us
to write something on the next line and have it be treated as being on the same line as above so now
if I run this code it gives me seven so that's one two three four five six seven that is correct and
if I delete these it should be one two three four five so let's just run this as well there it is
five and that's it so that's a bunch of different ways for us to get the last column again if you
want to understand the difference between these different methods and which one you should use
in which case I suggest you watch the first video where I show how to find the row number but for
this one that should be it thanks for watching please subscribe and I'll see you the next one