Excel VBA - Copy & Paste Help

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi everyone,

Need help creating VBA code to copy and past a cell range to another cell.

For example,

Cell A1 = 001
Cell A2 = 101
Cell A3 = 365

I would like to copy, paste and transpose cell range A1:A3 to cell range B1 keeping the same format.

For example, B1 would look like the following: 001,101,365 (place commas between the sets)

Thank you in advance!!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Maybe this
It does ALL cells in col "A"
If you don't want ALL cells, change the lr to the number of cells required
Code:
Sub MM1()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = 1 To lr
    If Range("B1").Value = "" Then
        Range("B1").Value = Range("A" & r).Value
        Else:
        Range("B1").Value = Range("B1").Value & "," & Range("A" & r).Value
    End If
Next r
End Sub
 
Upvote 0
Try
Code:
Sub Test()
    Range("B1").NumberFormat = "@"
    Range("B1") = Join(WorksheetFunction.Transpose(Range("A1:A3").Text), ",")
End Sub
 
Upvote 0
Thanks for all your help. I will use these examples.
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,208
Members
448,951
Latest member
jennlynn

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