Skip to main content
added 76 characters in body
Source Link
FaneDuru
  • 206
  • 1
  • 4

It is good to use offset and find empty cells just using (.Value = ""). Declaring all variables will also help you at debugging. If this will become a habit, it may be helpful in case of more complicated algorithms. No need to select anything for such an iteration. If you use VBA, why using formulas which will increase the workbook size?

Dim sh As Worksheet, rng As Range, cel As Range, lastRow As Long
  Set sh = ActiveSheet 'change it with your necessary sheet
   lastRow = sh.Cells(sh.Rows.count, "D").End(xlUp).Row
   Set rng = sh.Range("D1:D" & lastRow)
        For Each cel In rng
            If cel.Value = "" Then cel.Value = cel.Offset(0, -3)
        Next

It is good to use offset and find empty cells just using (.Value = ""). Declaring all variables will also help you at debugging. If this will become a habit, it may be helpful in case of more complicated algorithms. No need to select anything for such an iteration.

Dim sh As Worksheet, rng As Range, cel As Range, lastRow As Long
  Set sh = ActiveSheet 'change it with your necessary sheet
   lastRow = sh.Cells(sh.Rows.count, "D").End(xlUp).Row
   Set rng = sh.Range("D1:D" & lastRow)
        For Each cel In rng
            If cel.Value = "" Then cel.Value = cel.Offset(0, -3)
        Next

It is good to use offset and find empty cells just using (.Value = ""). Declaring all variables will also help you at debugging. If this will become a habit, it may be helpful in case of more complicated algorithms. No need to select anything for such an iteration. If you use VBA, why using formulas which will increase the workbook size?

Dim sh As Worksheet, rng As Range, cel As Range, lastRow As Long
  Set sh = ActiveSheet 'change it with your necessary sheet
   lastRow = sh.Cells(sh.Rows.count, "D").End(xlUp).Row
   Set rng = sh.Range("D1:D" & lastRow)
        For Each cel In rng
            If cel.Value = "" Then cel.Value = cel.Offset(0, -3)
        Next
Source Link
FaneDuru
  • 206
  • 1
  • 4

It is good to use offset and find empty cells just using (.Value = ""). Declaring all variables will also help you at debugging. If this will become a habit, it may be helpful in case of more complicated algorithms. No need to select anything for such an iteration.

Dim sh As Worksheet, rng As Range, cel As Range, lastRow As Long
  Set sh = ActiveSheet 'change it with your necessary sheet
   lastRow = sh.Cells(sh.Rows.count, "D").End(xlUp).Row
   Set rng = sh.Range("D1:D" & lastRow)
        For Each cel In rng
            If cel.Value = "" Then cel.Value = cel.Offset(0, -3)
        Next