Find and Replace with Change in Size and Left Align

sirmacademy

New Member
Joined
Aug 12, 2018
Messages
17
Greetings in ExcelLent World!
Please help me to find some ways to add some codes to add to change font size and alignment (left or right). Thank You@

Sub FindReplaceAlignSize()
Dim i As String
Dim k As String
i = "Signature"
k = "Verified as to the prescribed office hours:"
'Change the Range A1 and G1
With Range("A1", Range("A" & Rows.Count).End(xlUp))
.Columns(1).Replace what:=i, replacement:=k, lookat:=xlWhole, MatchCase:=False
End With
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi,
try

Rich (BB code):
Sub FindReplaceAlignSize()
    Dim i As String, k As String
    Dim firstaddress As String
    Dim rng As Range
    
    i = "Signature"
    k = "Verified as to the prescribed office hours:"
    
'Change the Range A1 and G1
    With Sheets("Sheet1").Columns(1)
        Set rng = .Find(what:=i, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
        If Not rng Is Nothing Then
            firstaddress = rng.Address
            Do
                With rng
                    .Value = k
                    .Font.Bold = False
                    .Font.Size = 12
                    .HorizontalAlignment = xlLeft
                End With
                Set rng = .FindNext(rng)
                If rng Is Nothing Then Exit Sub
            Loop While rng.Address <> firstaddress
        End If
    End With
    
End Sub

change sheet name shown in RED as required

Dave
 
Upvote 0
Hi,
try

Rich (BB code):
Sub FindReplaceAlignSize()
    Dim i As String, k As String
    Dim firstaddress As String
    Dim rng As Range
    
    i = "Signature"
    k = "Verified as to the prescribed office hours:"
    
'Change the Range A1 and G1
    With Sheets("Sheet1").Columns(1)
        Set rng = .Find(what:=i, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
        If Not rng Is Nothing Then
            firstaddress = rng.Address
            Do
                With rng
                    .Value = k
                    .Font.Bold = False
                    .Font.Size = 12
                    .HorizontalAlignment = xlLeft
                End With
                Set rng = .FindNext(rng)
                If rng Is Nothing Then Exit Sub
            Loop While rng.Address <> firstaddress
        End If
    End With
    
End Sub

change sheet name shown in RED as required

Dave

Nothing happens Sir.
 
Upvote 0
Nothing happens Sir.

Code will in sheet named "Sheet1" Column 1 - find value defined in variable "i" & replace it with value defined in variable "k"
It will also allow you to set Font Size, Alignment etc

If code is not working it is either not looking at correct worksheet (did you rename sheet as stated) or the search value defined in variable i does not exist in the range.

If still having problems, place copy of you workbook with sample data in a dropbox & provide link to it.

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

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