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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,922
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,922
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,102,593
Messages
5,487,755
Members
407,610
Latest member
bellakim00

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top