Find and Replace Within Range VBA

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello everyone:

I wrote a VBA code that would allow me to find and replace $ for Y I in column I. But also I need to replace blank cells in column I with N. The problem I have is that it fills all the blank cells down with N and I only need the cells within a range filled. In other words, there are 24 rows of data from I2 down, then search for Blanks and Replace with N in those 24 rows.

At the end of the code below you can see that I got to half my VBA, but I cannot figure out the replace blanks with N within range.

Any help will be appreciated

Private Sub CommandButton1_Click()

Sheets("byposition").Select
Rows("1:7").Select
Selection.Delete Shift:=xlUp
Columns("E:E").Select
Selection.Copy
Columns("A:A").Select
ActiveSheet.Paste
Cells.Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns("I:I").Select
Selection.Replace What:="$", Replacement:="Y", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
MsgBox "Step 1 Completed"
End Sub
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi

Maybe something like

Code:
Private Sub CommandButton1_Click()
Dim rws As Long
With Sheets("byemployee")
    .Rows("1:7").Delete Shift:=xlUp
    .Cells.Sort Key1:=Range("A2"), Order1:=xlAscending
End With
With Sheets("byposition")
    rws = .UsedRange.Rows.Count
    .Rows("1:7").Delete Shift:=xlUp
    .Columns("E:E").Copy
    .Columns("A:A").PasteSpecial
    .Cells.Sort Key1:=Range("A2"), Order1:=xlAscending
    .Columns("I:I").Replace What:="$", Replacement:="Y"
    .Range("I2:I" & rws).SpecialCells(xlCellTypeBlanks).Value = "N"
End With
MsgBox "Step 1 Completed"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,395
Messages
6,178,344
Members
452,841
Latest member
GenAkaman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top