Copy all text from a merged cell VBA

LordSnow548

Banned user
Joined
Apr 29, 2020
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a need to copy text from a set of merged cells using VBA by being able to click on a button, what i have thus far is:

Private Sub CommandButton2_Click()
'Copy Single cell
Range("E6:G28").Copy
End Sub

It works well, but its copying a lot of dead space and not just the text, so it copies the text and then several lines of just nothing at all, is there anything i can do to the above to only copy the visible text?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The size of Range("E6:G28") is 23 rows and 3 columns!
The cells may be be merged, but what cell exactly is the text entry made in?
Just copy the contents of that cell.

BTW, if you are using VBA, I HIGHLY recommend you get rid of merged cells! They cause nothing but issues for things like VBA, sorting, etc.
Most serious programmers will NEVER use them (any many will not touch any question that involves them).

For merging cells across single rows, the "Center Across Selection" formatting option works much better.
It gives you the same visual effect as merged cells, but without all the issues.
See: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis
 
Upvote 0
The size of Range("E6:G28") is 23 rows and 3 columns!
The cells may be be merged, but what cell exactly is the text entry made in?
Just copy the contents of that cell.

BTW, if you are using VBA, I HIGHLY recommend you get rid of merged cells! They cause nothing but issues for things like VBA, sorting, etc.
Most serious programmers will NEVER use them (any many will not touch any question that involves them).

For merging cells across single rows, the "Center Across Selection" formatting option works much better.
It gives you the same visual effect as merged cells, but without all the issues.
See: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis
Hey Joe,

Thanks for answer, i agree merged cells are the devil! Hence why im trying to find better options, the cell the entry is made in is E6, the cells were merged for aesthetics i guess, (Im not the original creator) and while it looked good it just isnt working well.

Ive had a look at the Center across selection and that seems to work great but is there a way to have the text aligned left and not centered? ( no big deal if this isnt an option) or is there a way to copy text from an activeX text box?

Thanks in advance,
 
Upvote 0
Center across selection and that seems to work great but is there a way to have the text aligned left and not centered?
If looking to left align, then why merge the cells at all???
I don't see the point of that of all.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top