Excel VBA - Copy & Paste Help

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
961
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,299
Messages
6,124,125
Members
449,142
Latest member
championbowler

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