How would you write this ?

sl1990

New Member
Joined
Jun 3, 2011
Messages
20
Hi how would you write this as a macro?

Copy X1,X3,X6,X9 and paste them into next available cell in the A column of a sheet called "result" in the same workbook.


Thanks in advance

Cheers!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi There,

This macro will do what you describe

Code:
Sub copycells()

    sResult = Range("x1") & " " & Range("x3") & " " & Range("x6") & " " & Range("x9")

    Sheets("result").Range("A" & Sheets("result").Range("A65536").End(xlUp).Row) = sResult
    

End Sub
Please note your post said that you want X1, X3, X6, X9 to be pasted "into next available cell". Therefore, I'm assuming that the four values are to appear in one cell.

Please let me know if you have any further queries this with
 
Upvote 0
Something like...


Code:
Sub foo()
Dim lst As Long
Dim i As Long
Dim item As Variant

lst = Sheets("result").Range("A" & Rows.Count).End(xlUp).Row
i = 1
For Each item In Array("X1", "X3", "X6", "X9")
    Sheets("result").Range("A" & lst + i) = Range(item)
    i = i + 1
Next item
End Sub
 
Upvote 0
Another one just a little shorter using Areas:

Code:
Sub test()
    Dim myArea As Range
    Dim LR As Long
    LR = Sheets("result").Range("A" & Rows.Count).End(xlUp).Row
    For Each myArea In Range("X1, X3, X6, X9").Areas
        Sheets("result").Range("A" & LR + 1) = myArea
        LR = LR + 1
    Next
End Sub
 
Upvote 0
Thanks so much Dfenton21, Dave3009, Nalani.

I found Dave3009's works best for me in this instance, Is there any way to make it copy the cells color across to the "result" sheet.?

cheers
 
Upvote 0
Try

Code:
Sub foo()
Dim lst As Long
Dim i As Long
Dim item As Variant

lst = Sheets("result").Range("A" & Rows.Count).End(xlUp).Row
i = 1
For Each item In Array("X1", "X3", "X6", "X9")
    With Sheets("result").Range("A" & lst + i) 
       .Value = Range(item).Value
       .Interior.Colorindex = Range(item).Interior.ColorIndex
    End With
    i = i + 1
Next item
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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