SOLVED

VBA code for blank cells

Iron Contributor

Hello Everyone,

I am trying to fill all the blank cells with "UNASSIGNED CUSTOMER" string. The problem i am facing is specifying the range of the loop that i want to run.

Since I want to make this as dynamic as possible.

I tried this code, but not working - 

 

Dim valueCells As Range

Dim valueRange As Range

set valueRange =

For Each valueCells In valueRange

If VBA.IsEmpty(valueCells.Value) = True Then

valueCells.Value = "Customer Unassigned"

End If

Next

 

Can you please help me out with the range here?

 

--Or--

 

What should i write in VBA code?

 

Please help..??

 

Here is a attached file..

4 Replies

@Excel 

You can't just write some lines of code in a module; you should create a macro or a function.

Try this:

Sub FillTheBlanks()
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Value = "UNASSIGNED CUSTOMER"
End Sub
Sir, What is the working of SpecialCells(xlCellTypeBlanks) ?
best response confirmed by Excel (Iron Contributor)
Solution

@Excel 

It returns the range containing all blank cells in the range specified before SpecialCells, in this code the used range of the active sheet.

See Range.SpecialCells method (Excel) and XlCellType enumeration (Excel) 

Thank you so much sir:smiling_face_with_smiling_eyes:
1 best response

Accepted Solutions
best response confirmed by Excel (Iron Contributor)
Solution

@Excel 

It returns the range containing all blank cells in the range specified before SpecialCells, in this code the used range of the active sheet.

See Range.SpecialCells method (Excel) and XlCellType enumeration (Excel) 

View solution in original post