+ Reply to Thread
Results 1 to 3 of 3

Simplification of VBA ranges

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2014
    Location
    Oxford, England
    MS-Off Ver
    365
    Posts
    66

    Simplification of VBA ranges

    Hi all,

    I'm looking for a way to simplify this code:

    Range("C12,D12,H12,I12") = "A"
    Range("C19,D19,H19,I19") = "B"
    Range("C26,D26,H26,I26") = "C"
    Range("C27,D27,H27,I27") = "D"
    Range("C29,D29,H29,I29") = "E"
    ... etc etc ...

    There are a lot of ranges, but the columns are always C, D, H & I. Is there anyway to simplify it so I can just have one row number for each range (eg Range("C,D,H,I & 12") = "A"?

    Any help would be greatly appreciated.

    Thanks,
    Jamie

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Simplification of VBA ranges

    Hello jamiem4,

    Here is one way...
            With Worksheets("Sheet1").Range("C1:D1,H1:I1")
                .Offset(12, 0).Value = "A"
                .Offset(19, 0).Value = "B"
                .Offset(26, 0).Value = "C"
                .Offset(27, 0).Value = "D"
                .Offset(29, 0).Value = "E"
            End With
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Simplification of VBA ranges

    Another method:

    Rows(12).Range("C1,D1,H1,I1") = "A"
    Rows(19).Range("C1,D1,H1,I1") = "B"
    Rows(26).Range("C1,D1,H1,I1") = "C"
    Rows(27).Range("C1,D1,H1,I1") = "D"
    Rows(29).Range("C1,D1,H1,I1") =  "E"
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. [SOLVED] Formula Simplification If/Or/And/Then/Else
    By snuffnchess in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-11-2016, 08:27 PM
  2. simplification de formule
    By Nacho15 in forum Non English Excel
    Replies: 14
    Last Post: 11-15-2013, 11:14 AM
  3. Sorting VBA Simplification
    By rmoreno in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-26-2013, 08:29 PM
  4. [SOLVED] Formula Simplification
    By brharrii in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2013, 10:46 AM
  5. if statement Simplification
    By sk81681 in forum Excel General
    Replies: 16
    Last Post: 06-05-2009, 05:24 AM
  6. Simplification help
    By Mike Smith NC in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-12-2006, 01:35 PM
  7. [SOLVED] Simplification help
    By Mike Smith NC in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-12-2006, 11:05 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