need VBA to fill in blank cells with the cell value or unique number

skyport

Active Member
Joined
Aug 3, 2014
Messages
374
Hoping someone can help with this one.

I need a VBA that can locate every blank cell in columns A-F and fill in each blank cell with the cell value or any other unique number so that every cell shows a different value rather than the blank cells all showing the same value.

I have currently been using the following but it doesn't always work:

Sub FillBlanksWithCellAddress()
Dim LastRow As Variant, Cell As Range
LastRow = Application.InputBox("What is the last row number?", Type:=1)
If LastRow = "False" Then Exit Sub
For Each Cell In Range("A1:F" & LastRow).SpecialCells(xlBlanks)
Cell.Value = Cell.Address(0, 0)
Next
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I don't know if I'm understanding what you need or if I'm grossly over-simplifying, but you can just highlight your data and run this:

Code:
Sub FillErUp()
    Selection.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=ADDRESS(ROW(),COLUMN())"
End Sub

It would certainly be faster than a For loop. And you can use it as is and manually highlight or do what you need to get your selection.
 
Upvote 0
Here's another option if you can't leave formulas in your data. It's a for loop, but only loops through your blanks rather than all cells.

Code:
Sub FillErUp()
    ActiveWorkbook.Names.Add Name:="Blanks", RefersToR1C1:=Selection.SpecialCells(xlCellTypeBlanks)
    
    Range("Blanks").Select
    
    For Each c In Selection
        c.Value = Chr(c.Column + 64) & c.Row
    Next c
End Sub
 
Last edited:
Upvote 0
Hi CWatts Thanks much for helping. First program worked perfectly and fast. Second one did not seem to do anything. If you care to play with it a bit, I can certainly give you feedback. However, first one does get the job done.
 
Upvote 0
If the first one is sufficient for your needs and the problem is solved, then that's good enough for me. :) Enjoy!
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

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