C Deepak
C Deepak

Reputation: 1278

Excel macro for data formatting

I have data in excel in following format

1 2  
3 4  
5 6  
7 8  
8 9   

I want output as : 1 2 3 4 5 6 7 8 9 in a single row

Upvotes: 1

Views: 169

Answers (1)

Alex K.
Alex K.

Reputation: 175776

Assuming

    A  B
========
1)  1  2
2)  3  4

Then this will put the data in C1:

Dim Data As Range, cell As Variant, buffer As String
Set Data = Range("A1:B1", Range("A1:B1").End(xlDown))

For Each cell In Data
    If (buffer = "") Then
        buffer = cell.Value
    Else
        buffer = buffer & " " & cell.Value
    End If
Next

Range("C1").Value = buffer

Upvotes: 2

Related Questions