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
CC10Asked:
Who is Participating?
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.

Martin LissOlder than dirtCommented:
I assume there are existing formulas involved. Can you attach your workbook?
0
CC10Author 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
0
Martin LissOlder 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

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

CC10Author 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
0
Martin LissOlder 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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
Martin LissOlder 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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.