Hope someone can help. I need to populate any blank/empty cells within a range of cells with a specific string. I also don't know that the last row would be in that range so I am looking for that first, I know that line of code works as I have used it for another function within the script. Below is the code I am using: -
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
For Each r In Range("AS22:AU" & LastRow)
If r.Value2 = vbNullString Then
r.Value2 = "Greens"
End If
Next
I don't seem to get any compile errors when I run the code, it just does not work, I still have the same blank/empty cells.
Can anyone shed any light onto what I am doing wrong?
In the popping up Find and Replace dialog box, under the Replace tab, keep the Find what box blank, enter the certain text you want to replace the blank cells into the Replace with box, and finally click the Replace All button.
In this method, we will use the REPLACE function to fill in the specific text with a blank cell. The REPLACE function in Excel replaces characters in a text string indicated by location with characters from another text string. In our dataset, we will create a duplicate of the Food Type column.
1. Select the range with blank cells you need to replace with certain content, then press Ctrl + H keys simultaneously to open the Find and Replace dialog box. 2. In the popping up Find and Replace dialog box, under the Replace tab, keep the Find what box blank,...
Using replace () method you can also replace empty string or blank values to a NaN on a single selected column. df2 = df. Courses. replace ('', np. nan, regex = True) print( df2)
You could just use the .Replace
Method with the range. It would be much quicker.
Range("AS22:AU" & LastRow).Replace "", "Greens", xlWhole
How about:
Sub dural()
Dim r As Range, LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
For Each r In Range("AS22:AU" & LastRow)
If r.Text = "" Then r.Value = "Greens"
Next r
End Sub
This will change:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With