Inserting Character When Using a Command Button to Copy Several Cells

bern75

New Member
Joined
Sep 19, 2017
Messages
5
This is actually a two-part question. While I have been using Excel for many, many years, I am new to the macro world. First, I'm building a spreadsheet that consolidates texts to one cell and I'm using a command button to copy that text. The code I'm using in the button click to copy the text is below. Is there any code that would be "better?" I ask this because, while this works, I know there is always a more efficient way or code that has less "overhead."

Sub Button1_Click()

Range("A1").Copy

End Sub


The second part is, there is another section of the workbook where I want to click a button and the text from several cells are copied. While I know I can use the code above with the range being something like "Range("A1:A4")," how would I copy text from several cells that are not sequential and I want to put a semicolon with a space between each cell I copied "; ". For example, if A1 had john@gmail.com, B4 had suzy@hotmail.com, and C7 had larry@outlook.com, click button1 would copy the three cells with a format like "john@gmail.com; suzy@hotmail.com**;** larry@outlook.com**"**

Thank you!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
@bern75
Re part 2. How are the cells that you will join determined?
Predetermined eg as A1, B4, C7. ?
Selected at runtime ?
Something else ?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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