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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,015
Office Version
2019
Platform
Windows
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
 

sirmacademy

New Member
Joined
Aug 12, 2018
Messages
17
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.
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,015
Office Version
2019
Platform
Windows
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:

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,856
Messages
5,507,735
Members
408,647
Latest member
Nicho la zido

This Week's Hot Topics

Top