# Excel macro to copy and paste different cells

I have 2 fixed cells C1 and C4
I have a column of cells D1 to D6
For each cell, D1 to D6, copy to C1 and then copy the result of C4 to a new column E1 to E6. So the result of C4 using cell D1(in C1) is shown in cell E1, the result of C4 using cell D2 (in C1) is shown in cell E2 and so on.

Then copy the column E1:E6 to the next free column. If F;G;H are filled, then the result would be pasted into column I1:I6.

Thanks,
CC
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
I assume there are existing formulas involved. Can you attach your workbook?
Author Commented:
The workbook is quite big so I have created a new one with the example and a macro. Basically I need the macro to loop through the rows and then copy to the next available column.

Thanks.
test.xlsm
Older than dirtCommented:
``````Sub MultiplyAll()
Dim lngRow As Long

For lngRow = 1 To 6
Range("C1") = Cells(lngRow, "D")
Cells(lngRow, "E") = Range("C4")
Next
End Sub
``````
Author Commented:
Thanks, that works fine but I still need an added part where the macro copies range E1:E6 to the next available column and saves values. If ranges f1:f6 and G1:G6 were filled, then it would copy to H1:H6
Older than dirtCommented:
``````Sub MultiplyAll()
Dim lngRow As Long
Dim intLastCol As Integer

intLastCol = Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, SearchDirection:=xlPrevious).Column + 1
For lngRow = 1 To 6
Range("C1") = Cells(lngRow, "D")
Cells(lngRow, intLastCol) = Range("C4")
Next
End Sub
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Older than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest youincluding these two new ones.
An Experts Exchange Shortcut for the Truly Lazy (for Apple OS X)
A Guide to Writing Understandable and Maintainable VBA Code
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.