+ Reply to Thread
Results 1 to 3 of 3

vba programming-xl

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    270

    vba programming-xl

    Hi All

    Can someone please tel me about the below three terms and when to use them . I have commonly seen them in excel vba code


    1) XLdown, xlsolid, xlautomatic...... .. The list is huge i guess, where can i get all the list and when to use them


    2) Selection : why do use this and when. I could see some examples like
    Selection.Interior.ColorIndex
    Selection.Interior.Pattern

    What i observed that when i type selection. i dont get any list which is prepopulated even after i type interior its the same
    so how can we know what to type after selection.

    3) With - When to use this and what for.

    I know point 2 & 3 seems like general english terms but how to know more about them and their usage in programming

    xl means excel is understood but what is this down/solid /automatic

    can some briefly explain about these three.

    thanx for u r time
    Last edited by grkchakri; 02-23-2012 at 12:28 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: vba programming-xl

    xlDown traverses down a column until the last used or unused cell
    xlSolid is more commonly used for colours
    xlAutomatic is another property for colours but I am unsure as to exactly what it does.

    Selection is an interesting subject. More experienced programmers do not use a selection statement unless there is a cell that needs to be selected. Using Selection makes Excel work a lot harder and also can make your screen jumpy. Your example could be re written with a range variable like:
    Please Login or Register  to view this content.
    If you declare Sheet Names, Range Variables, and other variables, you will be more likely to have that list pop up while typing code. For Instance:
    Please Login or Register  to view this content.
    Use With when you need to work on a range (for instance) but perform multiple actions on it like above. If we weren't to use them on the above, you would have to type out each line explicitly like:
    Please Login or Register  to view this content.
    Hopefully this helps a little.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: vba programming-xl

    xlAutomatic = returns the default excel font color which is black.
    xlDown tells excel which way to look for example to find the last used cell, before a blank in a Column:
    Please Login or Register  to view this content.
    x in this case is the last cell in column A with a value
    xlSolid - has to do with the way a cell is filled when formatting = to answer your with as well - with allows you to work with a range to do various things and will shorten you code - in this case formatting
    Please Login or Register  to view this content.
    By using the With Command I can apply formatting to a range and shorten the amount of code otherwise I would have to write
    Please Login or Register  to view this content.
    The xlSolid tells excel to format the cells in the range A2:B2 to color the cells with no pattern just solid yellow. It is equivalent to going format cells and selecting a background color with no pattern.
    The Selection term is used too much however with the example above you could have written
    Please Login or Register  to view this content.
    Select simply selects the range and then the Selection command refers to what you have selected. Really there is very little need to ever select - By using the select command I had to write an extra line of unnecessary code so avoid using Select and Activate. You will notice that if you use the macro recorder that it will write code very much like the last example however it writes what the user does and when you are recording a macro and then you select a range of cells then the macro recorder writes that to the macro - the macro recorder is good however you often end up with superfluous code. When you are learning it is good to look at the code generated and then see if you can shorten the code.
    Remember Google is your friend
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1