Forum Discussion

Alan Skelly's avatar
Alan Skelly
Copper Contributor
Aug 28, 2020
Solved

macro to copy and paste on loop example sent

read note in example file. sheet 1
  • Juliano-Petrukio's avatar
    Aug 29, 2020

    Alan Skelly 

    Hello, I hope I can help you

    Well, to be honest I didn't understand the main purpose of transfer all values from 1 cell to to another via code.

    But I can presume you are looking for something that can take piece of piece and then do this transferring. I prepare the following loop so you can use in your workbook.

    Remember that what this code is doing is breaking the names separated by comma and transferring one by one to another cell, just like you wrote. Please advise me if is something different from this.

     

    Sub TranferValuesbyLoop()
        Dim ListOfNames() As String
        ListOfNames = Split(Worksheets("sheet1").Range("D4").Value, ", ")
        
        Dim item As Variant, Destination As Range
        Set Destination = Worksheets("sheet2").Range("E4")
            
        For Each item In ListOfNames
            If Len(Destination) > 0 Then
                Destination.Value = Destination.Value & "," & item
            Else
                Destination.Value = item
            End If
        Next item
        
    End Sub

     

Resources