pincivma

Board Regular
Joined
Dec 12, 2004
Messages
203
Hi all

I wrote this simple code but it is taking a long time to run. Is there a faster running macro?

Range("BA9").Select
Do
ActiveCell.Select
If ActiveCell.HasFormula Then
ActiveCell.Select
Selection.Copy
ActiveCell.Offset(0, -48).Select
ActiveSheet.Paste
ActiveCell.Offset(0, 48).Select
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell = "."

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
you might consider testing to see if your offset already has a value
if you have formulas that are calculated after every worksheet change that will have an effect
how many rows are you working with
 
Upvote 0
You can also get rid of all the selects like
Code:
With Range("BA9")
   i = 0
   Do
      If .Offset(i).HasFormula Then .Offset(i, -48).Value = .Offset(i).Value
      i = i + 1
   Loop Until .Offset(i) = "."
End With
 
Upvote 0
Hi Fluff

I finally had a chance to try your formula and I got an error on the line Loop Until .Offset(i) = ".". I also wanted formulas to remain formulas and not change into values. So I changed your macro to the following and it worked. Plus it took about 5 seconds to run the 11,000 rows. Thanks or the code.

With Range("BA9")
i = 0
Do
If .Offset(i).HasFormula Then .Offset(i, -48).formula = .Offset(i).formula
i = i + 1
Loop Until Until ActiveCell = "."
End With
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0
See if this is quicker :
Code:
Dim r As Range, rng As Range, a As Range
Set r = Range("BA9:BA" & Cells(Rows.Count, "BA").End(xlUp).Row).Find(".")(0)
On Error Resume Next
If Not r Is Nothing Then
    Set rng = Range("BA9:" & r.Address).SpecialCells(xlCellTypeFormulas)
Else: Set rng = Range("BA9:BA" & Cells(Rows.Count, "BA").End(xlUp).Row).SpecialCells(xlCellTypeFormulas)
End If
On Error GoTo 0
If Not rng Is Nothing Then
    For Each a In rng.Areas
        a.Copy a.Offset(0, -48)
    Next
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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