Code Correction Required

Ekguy39

New Member
Joined
Oct 27, 2015
Messages
16
Hello,

the macro below autofills cells in column with the name above if the cell is blank. The code works well but doesnt stop with column A. for some reason it goes into Column B.

Can anyone correct the code please

Sub Autofill()
ActiveSheet.Columns("A:A").Select
Selection.Unmerge
ActiveSheet.Outline.ShowLevels RowLevels:=2
With Range(Range("A"), Cells(Rows.Count, 3).End(xlUp).Offset(, -1))
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This line of code refers to columns A:B...
Code:
Range(Range("A"), Cells(Rows.Count, 3).End(xlUp).Offset(, -1))

Try this :

Code:
 Sub Autofill()
Dim LastRow As Long
Application.ScreenUpdating = False
With ActiveSheet
    .Columns("A:A").UnMerge
    .Outline.ShowLevels RowLevels:=2
    
    LastRow = .Cells(Rows.Count, 3).End(xlUp).Row
    
    With Range(.Cells(2, 1), .Cells(LastRow, 1)).SpecialCells(xlCellTypeBlanks)
        .Formula = .Offset(-1).Value
    End With
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Its not working properly. The macro before would copy down the data until it came to a populated cell, then it would copy down the new data until again it hit new data. The macro now just copies down the data from the frist cell A7 but doesnt do what it did previously with new data.
 
Upvote 0
is there anyway to change this line of code to just look at column A

Range(Range("A"), Cells(Rows.Count, 3).End(xlUp).Offset(, -1))
 
Upvote 0
Its not working properly. The macro before would copy down the data until it came to a populated cell, then it would copy down the new data until again it hit new data. The macro now just copies down the data from the frist cell A7 but doesnt do what it did previously with new data.

Your code doesn't copy anything. It writes a formula to blank cells within the selected range then converts it to a value. My code does the same without selecting the range or using a formula.

You haven't provided a sample of your data, so don't understand what you mean by old or new data.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

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