mickyflash
Board Regular
- Joined
- Jan 29, 2009
- Messages
- 77
Hi I would like to have a VBA code that enters the word "search" into B20 if B20 is blank.
I do not want this to be a formula as I will require the user to enter text into B20
I know very little about VBA and have found the following codes that seem to do similar but I cant seem to adapt them, here is what I have below:
or
Can anyone see what I am doing wrong?
I do not want this to be a formula as I will require the user to enter text into B20
I know very little about VBA and have found the following codes that seem to do similar but I cant seem to adapt them, here is what I have below:
Code:
Option Explicit
Sub RangeSetEmpty()
Replace_Blanks [b20], "Search"
End Sub
Sub Replace_Blanks(rangeToEmpty As Range, replacementText As String)
Dim cell As Range
For Each cell In rangeToEmpty
If cell.Value = "" Then cell.Value = replacementText
'Application.Goto Reference:=rangeToEmpty
Next cell
End Sub
or
Code:
Sub Replace_Blanks()
Application.Goto Reference:="B20"
Selection.Replace What:="", Replacement:="Search",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
Can anyone see what I am doing wrong?