Find Next Empty Cell in Row

temerson

New Member
Joined
Apr 22, 2019
Messages
39
I need a code where:

1. It will find the next empty cell in row 1
2. add text to this empty cell
3. auto fill a formula down to the last non-empty cell

I have something similar below, but it is not dynamic.

VBA Code:
Range("L1").FormulaR1C1 = "CASE QTY"
    Range("L1").Select
   
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.249977111117893
        .PatternTintAndShade = 0
    End With
    With Selection
        .Font.Bold = True
    End With
    Range("L2").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    ActiveCell.FormulaR1C1 = "1"
   
    Selection.AutoFill Destination:=Range("L2:L" & Range("K" & Rows.Count).End(xlUp).Row)
    Range(Selection, Selection.End(xlDown)).Select
 

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
VBA Code:
Sub go()

fr = Range("L1").End(xlDown).Row + 1 'first row

Cells(fr, "L").Select
ActiveCell.Value = "CASE QTY"
'.....do other stuff it you an too


lr = Cells(fr, "L").End(xlDown).Row - 1 'last row
Range("L" & fr & ":L" & lr).FillDown

End Sub

hth,

Ross
 
Upvote 0
Maybe...
Code:
Sub lastx3()
Dim myRng As Range
    With Cells(1, Rows(1).Find("*", , xlValues, , xlByColumns, xlPrevious).Column).Offset(, 1)
       
        .Value = "CASE QTY"
       
        With .Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.249977111117893
            .PatternTintAndShade = 0
        End With

        .Font.Bold = True
   
Set myRng = .Offset(1)
End With
    With Range(myRng, Cells(Columns(myRng.Column - 1).Find("*", , xlValues, , xlByRows, xlPrevious).Row, myRng.Column))
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        .Borders.Weight = xlThin
        .Value = 1
    End With

End Sub
If you have an actual formula as per your question (you haven't posted a formula, you have posted a string) then change
VBA Code:
.Value = 1
to
VBA Code:
.Formula = "your formula, doubling up any quotes"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,884
Messages
6,122,082
Members
449,064
Latest member
MattDRT

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