VBA - How can I copy ONLY text from one range and paste ONLY the first three text on another sheet

zgivod

New Member
Joined
Dec 6, 2018
Messages
17
I have up to 6 cells with potential data coming from 6 different places. I am trying to get only the first three cells with data transferred to another sheet
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private Sub Transfer_Data()

Sheets
("sheet1").Range("A1:A6").SpecialCells(xlCellTypeConstants, 23).copy

Sheets
("sheet2").Range("A1:A3").PasteSpecial Paste:=xlPasteValues

Application
.CutCopyMode = False

End Sub</code>This is what i have i know i am missing allot. thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Kind of crude but it works.

Code:
Sub t()
Dim ary As Variant, i As Long, x As Long
ary = Application.Transpose(Range("A1:A6"))
    For i = 1 To UBound(ary)
        If ary(i) <> "" Then
            x = x + 1
            Sheets(2).Range("A" & x) = ary(i)
            If x = 3 Then Exit For
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Kind of crude but it works.

Code:
Sub t()
Dim ary As Variant, i As Long, x As Long
ary = Application.Transpose(Range("A1:A6"))
    For i = 1 To UBound(ary)
        If ary(i) <> "" Then
            x = x + 1
            Sheets(2).Range("A" & x) = ary(i)
            If x = 3 Then Exit For
        End If
    Next
End Sub
Assuming the pipe symbol (|) will never be found in the text of any cell, here is another way to write this macro...
Code:
[table="width: 500"]
[tr]
	[td]Sub FirstThreeTextCells()
  Dim Combo As String
  Combo = Replace(Replace(Join([TRANSPOSE(A1:A6)], "|"), "|||", "|"), "||", "|")
  Sheets(2).[A1:A3] = Application.Transpose(Split(Mid(Combo, 1 - (Left(Combo, 1) = "|")), "|"))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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