Using Replace Programmatically to Set the Correct Range : Cells « Excel « VBA / Excel / Access / Word






Using Replace Programmatically to Set the Correct Range

 
Sub ReplaceExample() 
    Dim ws As Worksheet 
    Dim rg As Range 
    Dim lLastRow As Long 

    Set ws = ThisWorkbook.Worksheets("Replace Examples") 
    lLastRow = ws.Cells(65536, 1).End(xlUp).Row 
    Set rg = ws.Range(ws.Cells(2, 2), ws.Cells(lLastRow, 3)) 
    rg.Replace "", "UNKNOWN" 
    Set rg = ws.Range(ws.Cells(2, 4), ws.Cells(lLastRow, 4)) 
    rg.Replace "", "0" 

    Set rg = Nothing 
    Set ws = Nothing 
End Sub 

 








Related examples in the same category

1.Select entire sheet
2.Set cell value with For Loop
3.Use row and column index to reference cell
4.Cells(Rows.Count, "A").End(xlUp).Select
5.looping through a worksheet range using a For/Next loop.
6.Cells.Find: Get Real Last Cell
7.Get cell value
8.Sum Cells Based on the Interior Color
9.Entering a value in the next empty cell
10.Use the AutoFill function by specifying the destination range
11.Calling CurrentRegion to Inspect a List's Useful Characteristics