Loop inside an excel macro, please help

Nagini

New Member
Joined
Dec 11, 2016
Messages
34
Hello! I'm absolutely ignorant of excel! I''m designing a macro but it is so slow because It's too long. I have read some posts here and I thing that a loop could accelerate its performance.

The concept is easy but I don't know how to do it, I'm sure that you can help me. I'm sorry for my english, I'm from another country!!

Here is the macro I'm writing:

' Macro1 Macro
'
Sheets("Hoja2").Select
Range("B1").Select
Selection.Copy
Sheets("Historico").Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Run "Hoja1.btnAceptar_Click"
Range("B7").Select
Range("B7:B400").Select
Selection.Copy
Sheets("Hoja2").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Hoja2").Select
Range("C1").Select
Selection.Copy
Sheets("Historico").Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Run "Hoja1.btnAceptar_Click"
Range("B7").Select
Range("B7:B400").Select
Selection.Copy
Sheets("Hoja2").Select
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
End Sub

What I want to do is a loop to start copying B1 but then C1, D1, E1, etc.

And then paste the result in B5, C5, D5, E5, etc.

Is there a way to do it automatically ans thus reduce dramatically the length of the macro??
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi

This doesn't really match what your macro is doing, but is this what you want? Copies whatever is in B1:F1 and puts it in B5:F5. Change the ranges to suit.

Sub test()
Range("B5:F5").Value = Range("B1:F1").Value
End Sub

Regards

Murray
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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