macro to fill down values across multiple columns

sashazaliz

New Member
Joined
Nov 9, 2009
Messages
46
I'm working with the below macro which works on the first column by filling down the values from the row above in order to create a flat file format. My issue is I need the macro to perform this function on the first 3 columns. Is there a tweak to the code somebody could reccommend for me? thanks!:)

Code:
Sub InsertManufNames()
'the purpose of this macro is the insert the mfr names where they come in blank
     ActiveCell.SpecialCells(xlLastCell).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlUp).Select
 LastRow = ActiveCell.Row + 1
For I = 1 To LastRow
If Cells(I, 1) <> "" Then
    If Cells(I + 1, 1) = "" Then
    Cells(I + 1, 1) = Cells(I, 1)

End If
End If
Next I
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this

Code:
Sub fillin()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A1:C" & LR)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub
 
Upvote 0
thanks for your reply VoG. It filled the first 3 columns with REF# and not the actual values from the rows above. The original macro I pasted does work but just for the first column. Is there a way we can just tweak that macro to work across the first 3 columns? thanks
 
Upvote 0
Odd, that worked for me.

Try

Code:
Sub fillin()
Dim LR As Long, c As Range
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A1:C" & LR)
    For Each c In .SpecialCells(xlCellTypeBlanks)
        c.Value = c.Offset(-1).Value
    Next c
End With
End Sub
 
Upvote 0
Code:
Sub InsertManufNames()
'the purpose of this macro is the insert the mfr names where they come in blank
     ActiveCell.SpecialCells(xlLastCell).Select
    Selection.End(xlToLeft).Select
    Selection.End(xlUp).Select
 LastRow = ActiveCell.Row + 1
For I = 1 To LastRow
If Cells(I, 1) <> "" Then
    If Cells(I + 1, 1) = "" Then
    Cells(I + 1, 1) = Cells(I, 1)
 End If
End If
Next I
End Sub

Try instead for your loop:
Code:
For j = 1 to 3
For I = 1 To LastRow
If Cells(I, j) <> "" Then
    If Cells(I + 1, j) = "" Then
    Cells(I + 1, j) = Cells(I, 1)
End If
End If
Next I
Next j

That should get your first three columns. Good luck!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,912
Members
452,949
Latest member
beartooth91

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