+ Reply to Thread
Results 1 to 5 of 5

Macro to Merge cells A - D if cell B is blank in user defined selection

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Macro to Merge cells A - D if cell B is blank in user defined selection

    Hi Team,

    I'm trying to work our a macro that, within a user defined selection, will identify whether there is a value in cell B.

    If NO value is present in cell B then the macro should merge cells B to D of the row and then go to next row and start again.

    Basically,

    The user simply
    1. selects a range (could be a range (e.g. A5:D22) or a number of rows)
    2. activates the macro

    A range (greater than a single cell) MUST be selected. If no range is selected then an error message is displayed.

    The "Desired" tab in the attached indicates the outcome (on the original tab - a new tab is not required) assuming only Range A5:D22 is selected.

    Thanks all

    MM
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to Merge cells A - D if cell B is blank in user defined selection


    Hi,

    if it is always for columns A:D so in order to simplify why not just selecting only column B cells ?

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Macro to Merge cells A - D if cell B is blank in user defined selection

    Hi Marc,

    That works too. Yes, always Cols A to D where B is empty

    I'm pretty relaxed on what actually needs to be selected, just as long as it only operates on the user's selection
    Last edited by MagicMan; 07-21-2023 at 12:03 PM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Macro to Merge cells A - D if cell B is blank in user defined selection


    Try this VBA demonstration only with a contiguous column B selection :

    PHP Code: 
    Sub Demo1()
            
    Dim Rc As Range
            
    If Selection.Column <> Or Selection.Columns.Count Or Selection.Areas.Count 1 Then Beep: Exit Sub
        
    If Application.CountBlank(SelectionThen
            
    For Each Rc In Selection.SpecialCells(4):  Rc(10).Resize(, 4).Merge:  Next
            Selection
    .Select
        End 
    If
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-21-2023 at 12:22 PM.

  5. #5
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    Work Office 365 Home 2019
    Posts
    427

    Re: Macro to Merge cells A - D if cell B is blank in user defined selection

    Marc L

    Perfect, did the job bang on!

    (Rep added)

    MM

+ 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. data entry to defined cells in a table from a seperate user input selection section
    By JarJarBiscuits in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2022, 01:22 PM
  2. How to move cell contents using a user-defined macro
    By CaptainU in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2019, 11:17 AM
  3. [SOLVED] user defined selection box
    By nicody in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-07-2018, 02:46 PM
  4. Merge several cells into one cell separated by a defined character
    By kian82 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2017, 12:30 PM
  5. Replies: 8
    Last Post: 05-19-2008, 05:11 AM
  6. all user defined cell format del using macro
    By x taol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2005, 09:58 PM
  7. all user defined cell format del using macro
    By x taol in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-24-2005, 08:20 PM

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