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 to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,027
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,027
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,106,304
Messages
5,510,503
Members
408,792
Latest member
S_s_s

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top