Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update an Empty Cell in a range

I’m looking to update a cell on a sheet when it’s left empty. If there is data in column B but not in column AA, I need to insert something into column AA.

I have made the following code but have failed to make it update the cell:

Range("B2").Select
        Do Until IsEmpty(ActiveCell)
            Dim LoopRowNo As Integer
            LoopRowNo = ActiveCell.Row
            
            If IsEmpty(Range(Cells(LoopRowNo, 26))) Then Range(Cells(LoopRowNo, 26)).Value = "01/01/1990"
            ActiveCell.Offset(1, 0).Select
        Loop

Hoping someone can point me in the right direction.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  • Use Range or Cells, but not both.
  • Don’t Select.
With ActiveSheet
    Dim lastRow As Long
    lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

    Dim i As Long
    For i = 2 to lastRow
        If IsEmpty(.Cells(i, "AA")) And Not IsEmpty(.Cells(i, "B")) Then
            .Cells(i, "AA").Value = "01/01/1990"
        End If
    Next
End With
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading