Autofill VBA

AlexPi

Board Regular
Joined
Apr 4, 2011
Messages
104
I have some code that i'm using to fill in cells with the name that is in the cell above it...It seems to work but is taking a really long time. I use the same code on another worksheet and it takes a minute or so to finish but when I run it again on another sheet is is so slow that I've never waited long enough for it to finish!

Both sets of data are about the same length

Any ideas?

Code:
Sub AccountFillDown()
ActiveSheet.Range("A2:A65536").Select
For Each cell In Selection
If cell.Value = "" Then cell.Value = cell.Offset(-1, 0).Value
If cell.Offset(0, 1).Value = "Net Income" Then Exit Sub
 
Next
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Right off the bat changing screen updating and calculation always does wonders. Since your going cell by cell excel has to redraw the screen and recalculate after each iteration. This makes it only do it once when the macro is done.

Code:
Sub AccountFillDown()
Application.ScreenUpdating = False
Application.Calculation = xlManual
ActiveSheet.Range("A2:A65536").Select
    For Each cell In Selection
    If cell.Value = "" Then cell.Value = cell.Offset(-1, 0).Value
    If cell.Offset(0, 1).Value = "Net Income" Then Exit Sub
    Next
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Those two statements are in almost every single macro I write for just that reason. :) Glad it worked.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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