+ Reply to Thread
Results 1 to 4 of 4

Merging cells with VBA

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Merging cells with VBA

    I am using the following code to enter month names at given places on a work sheet.
    Please Login or Register  to view this content.
    MonthAr is an array carrying the month names as a single column.
    The code is meant to give every 20th column, starting at J the name of a month taken from the array. Cells J3 andK3 are merged and the month name is centralized
    The merging is supposed to happen with every 20th pair.
    The actual result is a bit different.
    DECEMBER is dealt with as expected all the other months are placed in the second cell (ie 20 cols from K not J). The pair of cells is not merged. The name is centred in its cell not its merged pair.
    Where am I going wrong?
    John

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Merging cells with VBA

    Maybe like this ?
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,409

    Re: Merging cells with VBA

    Quote Originally Posted by j_Southern View Post
    I am using the following code to enter month names at given places on a work sheet.
    Please Login or Register  to view this content.
    Quote Originally Posted by porucha vevrku View Post
    Maybe like this ?
    Please Login or Register  to view this content.
    Here is another way to assign the month names to the MonthAr variable that does not require you to maintain a list the month names on any of your worksheets (note that the MontAr variable must be declared as a Variant variable without any parentheses attached to the variable name in your Dim statement)...
    Please Login or Register  to view this content.
    At this point the MonthAr array is one-based, one-dimensional array. You would iterate it like this... MonthAr(1), MonthAr(2), MonthAr(3), etc.
    Last edited by Rick Rothstein; 10-24-2020 at 12:34 AM.

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Merging cells with VBA

    porucha vevrku and Rick Rothstein,
    Thank you both for your suggestions. Both have been incorporated in my project and both are working perfectly. I just had to change the increment of b to 20.
    I cant mark the thread as solved. Has the method changed?
    John

+ 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. Macro for Merging Cells based on empty cells in same sheet
    By mattfleet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2018, 09:26 AM
  2. [SOLVED] Help Auto-Merging Cells with merged cells already present
    By jenksbj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2016, 08:27 AM
  3. [SOLVED] How to combine similar cells, while merging data in other cells
    By Sut703 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-27-2014, 04:17 PM
  4. Replies: 6
    Last Post: 01-15-2012, 08:57 AM
  5. Merging cells/merging cell content.
    By rhintintin in forum Excel General
    Replies: 3
    Last Post: 09-23-2010, 10:42 AM
  6. Help with Merging Cells
    By kimmyh3 in forum Excel General
    Replies: 13
    Last Post: 08-28-2009, 04:34 PM
  7. Merging cells
    By sonic in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-16-2005, 09:08 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