Forum Discussion
VBA code for blank cells
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..
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)
4 Replies
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
- ExcelIron ContributorSir, What is the working of SpecialCells(xlCellTypeBlanks) ?
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)