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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,912
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
5,912
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:

Watch MrExcel Video

Forum statistics

Threads
1,101,914
Messages
5,483,688
Members
407,399
Latest member
Rakeforms

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top