Excel VBA - Alignment

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we'll see how to work on the alignment part when I say alignment part I'm talking about this alignment I have some text which is given in this area okay I want to align in two different position vertically and horizontally so how do I work on it so usually what we do is we select the data okay and we go to this alignment group in the Home tab and then we keep on selecting this values there are six different areas so this is top alignment middle alignment bottom alignment you see that's vertically it is going for changing position I'll do it again top middle and the bottom okay similarly if you want to go in the horizontal manner there's given us bottom and left middle and right so this one is left middle and right so these are there so I will just keep my cursor on those area and you can see what is given here it says as top align second one says as the middle align and third one it says as bottom align top middle and the bottom align if I go to this place it says align left center and it gives us align right so these are different names that are given but how do I work with help of this macro VBA if I want to change the alignment of this area see the sale a sell area that is a1 to c5 I have data in a1 to say five how do I change the alignment with help of macro let us see that so right now in the shield if you see that is K underscore alignment I have written the data here Excel VBA is the file name okay and I've created here I'll minimize this I have created a module that is K underscore alignment in this alignment module I have created sub alignment that's a sub procedure here and now I have written some text here okay let me explain you for the first time how it is written if I want to change the alignment of this data first thing is I have to give the range range a 1/2 if c5 range a1 to c5 and I want to change the alignment so you can see here range a want to see 5 dot and if you want to change the horizontal alignment you have to type as horizontal and Europe to see this alignment so press at app okay now once you press horizontal alignment I will just move the screen okay and then you put a space type equal to and you can put what alignment you want in the horizontal you'll get us left right Andy Center part so I'll write as Excel left okay that's the that's it so range a one to c5 dot horizontal alignment equal to X and left so if you remember for horizontal we have left right and we had the center so same thing if you copy/paste I have done the same thing here Excel left Excel right and Excel center so this three have written here same way if you want the vertical alignment instead of horizontal alignment you can put as range a one to see five vertical alignment equal to here it comes left right and center here will come as top bottom and centre okay vertical top bottom and between centers so this will get it I have written here in single quotes that's the comment part vertical alignment horizontal alignment so let us see that if I execute step-by-step you can observe what will happen here I'll just move the screen like this so you can see now if you want to execute step by step I'll click on this step into okay again I'll click on step into so now it will say as Excel left right now they are on the right I want them Excel left if I click on the step and do you observe you want to see if I bend on the left hand side again it is on the same thing a one to see five left again if I click on this place okay you see that it is changing the position here if I click on step into now it will become for the vertical alignment as the top now it is on the top position if I click on this I want in the bottom part I'll just click on this place you see everything came in the bottom and the last one is nothing but Excel center so I'll just click on this Excel center now everything has come into the middle part in the horizontal as well as the vertical manner both are in the center part and I will just click on this step into and finally it is done right so I hope you able to understand how do we work on the alignment part using the macros VB it is very very simple arrange dot horizontal alignment or range dot vertical alignment that's it and you can put the values itself that's all for this video and I hope you have understood thank you
Info
Channel: Tutorialspoint
Views: 161,338
Rating: undefined out of 5
Keywords: VBA, Marcos, Microsoft, Excel VBA, Excel VBA - Alignment, Alignment
Id: DJ7lyMkSn4Q
Channel Id: undefined
Length: 4min 3sec (243 seconds)
Published: Mon Jan 15 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.