• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

A Macro For Merge Cells

hoomantt

Member
I want a Macro For Merge Cellsthat select with mouse drag with a short key(e.g Ctrl+Q),That they Are In A Column(Such as column A)
these cells just countains data in first cell.
for example i want to merge cells A5:A12 with Short Key (Ctrl + Q) that just there is one data in just first cell(A5) and there are not any data in othere cells with Select Cells And Click Short key (Ctrl+Q)
And if it possible , can do this :
When i Select First Cell (Like A5) and drag for select end cell (Like A12) ; when i unhand the right mouse key , with a macro do merge cells and dont need to click short key or ....
may it?
Thanks to every Professors...
 
Hi Tehrani ,

Can you check this file for the Worksheet_SelectionChange macro ?

Narayan
 

Attachments

  • Example_Tehrani.xlsm
    10.1 KB · Views: 8
Good day hoomantt

Do you have to merge cells...................


Avoid merging cells
Merged cells can help you arrange values in a meaningful way, but they come with problems, numerous problems, big problems.

For instance, Excel won't apply column formats to a merged cell unless you select all the columns that comprise the merge.

In addition, not all cell formats stick once you unmerge a cell.

You can't sort a column with merged cells.

You can't even select a single column range if there's a merged cell in it -- go ahead, try!, the whole column will become merged, not good.

You cannot put a filter on it. The problem is the filter is completely useless because the filter will groan with the "merged cells need to be identically sized." Warning, which in English means you have to make each group of merged cells the same size as the largest group. And you have to find them all! Which can be done with Find and Replace but it is still more unneeded work.

Merging cells in columns and rows could lead to data lose, bad thing.

Formulas and Functions that refer to merged cells will not work, bad thing.

Don't hesitate to use merged cells if you really need them (you don’t), but they will limit what you can do to the cells and even the columns involved.

Center Across Selection is a far better alternative to merging.

To apply this format, select the cells you want to appear merged and then launch the Alignment group dialog, Ctrl + 1, and click the Alignment tab. Center Across Selection is in the Horizontal drop-down.

You will get the desired look you want but without the merged cells problems.
 
hi m
Hi Tehrani ,

Can you check this file for the Worksheet_SelectionChange macro ?

Narayan

hi my dear friend
your file is good and thank you for your help.
but i want a short key (e.g Ctrl+Q) for do this job.
please if you want help me....
 
Hi Tehrani ,

Can you check the file now ? I have used CTRL + q , not CTRL + Q.

Narayan
 

Attachments

  • Example_Tehrani.xlsm
    11.8 KB · Views: 7
Hi

Try this code. To assign short cut key, hit Alt+F8 > Options and assign the required key.

Code:
Sub MergeSelection()
    If TypeOf Selection Is Range Then
        Application.DisplayAlerts = False
        Selection.Merge
        Application.DisplayAlerts = True
    End If
End Sub
 
Back
Top