+ Reply to Thread
Results 1 to 7 of 7

VBA Format Multiple Ranges

  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Format Multiple Ranges

    Hi, I wonder whether someone may be able to help me please.

    I'm relatively new to VB, so a lot of my code is very long winded, an example of which is below:

    Please Login or Register  to view this content.
    The code applies formatting to two ranges within a given sheet in my workbook, but as I mentioned at the start, it's messy and 'long winded'.

    I just wondered whether someone with more experience, could possibly look at this please and offer some guidance on how I may be able to streamline the code.

    Many thanks and kind regards
    Last edited by hobbiton73; 11-21-2013 at 04:30 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Format Multiple Ranges

    You can replace:
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Format Multiple Ranges

    Hi @yudlugar, thank you very much for taking the time to reply to my post and the guidance.

    May I ask, is there a way in which I could streamline the coede any further.

    Many thanks and kind regards

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Format Multiple Ranges

    If you upload a workbook with a description of what the code is supposed to do, and the code in full. I could try and write it from scratch? I'd expect I would aim up with something very similar to what you have though.

    That said, you don't need to do the ranges separately. For example, instead of:
    Please Login or Register  to view this content.
    I could do:
    Please Login or Register  to view this content.
    If you are unsure of the exact way to build the string to select the different ranges, you could always use union:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Format Multiple Ranges

    Hi @yudlugar, thank you for your continued help with this, and my apologies for not replying sooner.

    Your offer of re-writing my code is very generous, but I wouldn't want to put you to anymore trouble. I would also like to see this thorugh because I am very keen to gain my knowledge and confidence in writing the code.

    Your last post was very inetresting because I wasn't aware of the
    Please Login or Register  to view this content.
    method of writing for multiple ranges.

    All the best and kind regards

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Format Multiple Ranges

    for info:
    Range("A1,C3")
    selects cells A1 and C3
    Range("A1","C3")
    selects cells a1,a2,a3,b1,b2,b3,c1,c2,c3

  7. #7
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Format Multiple Ranges

    Hi @yudlugar, thank you for coming back to me with this. This is extremely helpful.

    All the best and kind regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 03-19-2013, 07:03 PM
  2. Compiling multiple ranges of cells from multiple sheets into one grand table ?
    By teacher_rob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2012, 11:42 AM
  3. Replies: 0
    Last Post: 10-15-2012, 07:24 AM
  4. Replies: 8
    Last Post: 01-07-2011, 07:36 AM
  5. Replies: 4
    Last Post: 11-22-2005, 01:30 AM

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