I am working on a workbook that imports data from Access to Excel and need to figure out how to replace values in certain columns with a default date value when the cell is null. I have 24 columns that are not ordered next to each other that have date values in them, but there are blanks. I was attempting to use a select
range code to select the range and replace the value, but I run into issues with the range isn't contiguous. I was thinking that I could use another column that is almost always filled out to identify the end of the range count and continue to do the null replacement that I started with but I don't know how to do that. Is there a way to accomplish this easily? Here are the codes that I am working with now:
Sub replace_blanks()
Dim cellvar As Range
For Each cellvar In Selection.Cells
If cellvar.Value = vbNullString Then
cellvar.Value = "1/1/1900"
End If
Next cellvar
End Sub
and
Sub AfterImport()
Range("B1", Range("B1").End(xlDown)).Select
End Sub
Update:
Sub AfterImport()
Dim cellvar As Range
Dim AccessData As Worksheet
Dim lngLastRow As Long
Set AccessData = Worksheets("AccessData")
With AccessData
lngLastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
Range("B1", "B" & lngLastRow).Select
For Each cellvar In Selection.Cells
If cellvar.Value = vbNullString Then
cellvar.Value = "1/1/1900"
End If
Next cellvar
End With
Note: This last section of code works when the active sheet is the AccessData sheet. However, when I run it on another sheet I get an error and the macro quits.
Thank you.