one liner required

RET79

Well-known Member
Joined
Mar 19, 2002
Messages
526
I need to put the cells(2,4), Cells(3,5), cells(8,3) into Range("A1:A3") in a different workbook.

A one liner in VBA code would do the trick.

Any suggestions, thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi ret
assuming that the sehhet with the cells is the selected one

Sheets(2).Range("a1:a3") = WorksheetFunction.Transpose(Array(Cells(2, 4).Value, Cells(3, 5).Value, Cells(8, 6)))

regards Tommy
 
Upvote 0
On 2002-03-23 10:19, RET79 wrote:
I need to put the cells(2,4), Cells(3,5), cells(8,3) into Range("A1:A3") in a different workbook.

A one liner in VBA code would do the trick.

Any suggestions, thanks.

Hi,

Since you are going to have to reference two workbooks, a single line of code will be a mess to look at and debug.

---begin VBA---
Sub test()

Set orig = ThisWorkbook.Sheets("Sheet1")
Set dest = Workbooks("TestBook.xls").Sheets("Sheet1")

listarray = Array(orig.Cells(2, 4), orig.Cells(3, 5), orig.Cells(8, 3))
dest.Range("A1:A3") = WorksheetFunction.Transpose(listarray)

End Sub
---end VBA---

Bye,
Jay
 
Upvote 0
If you really need a one-liner, then if (and only if) the source sheet is the active sheet, the shortest code is probably :-

Workbooks("TestBook.xls").Sheets("Sheet1").[A1:A3].Value = WorksheetFunction.Transpose(Array([D2], [E3], [C8]))

If the source sheet is not the active sheet, then as Jay Petrulius mentions, a one-liner would be a bit unweildy.
 
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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