VBA Help - Search range for cells with text and Align text to the Right and Increase Font Size

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello all,

working on a code that needs to be able to search a specific range Sheet1.Range("N15:EM134") Once found process the below actions:
  • Align text to the right of the cell
  • Increase the font size of the found text to size 15
Alternatively, I would need to do the same thing in the same range but for cells with numbers only:
  • Align text to the center
  • Decrease font size to 11
  • *One exception, there will be cells with only numeric values that contain a dash (example: "1-5")
Any help on this would be greatly appreciated. This was the one piece of the puzzle that I am not really knowledgeable on doing.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Oh darn, sorry. I just realized when I was formatting my message I deleted a sentence in there.

This is what it should have said,

working on a code that needs to be able to search a specific range Sheet1.Range("N15:EM134") for Text only, Once found process the below actions:
  • Align text to the right of the cell
  • Increase the font size of the found text to size 15
Alternatively, I would need to do the same thing in the same range but for cells with numbers only:
  • Align text to the center
  • Decrease font size to 11
  • *One exception, there will be cells with only numeric values that contain a dash (example: "1-5")
Any help on this would be greatly appreciated. This was the one piece of the puzzle that I am not really knowledgeable on doing.

I have come up with a quick solution that works but it is not ideal and super fast but it gets the job done.

VBA Code:
'-----------------------------------------------------
'--- Resets formulas on Timeline
'-----------------------------------------------------
Sub ResetFormulas()

Dim ws1 As Worksheet
Dim cell As Range, DataTable As Range, Rng As Range, DataTable2 As Range

Set ws1 = Sheets("Timeline")
LastR = ws1.Range("C" & Rows.Count).End(3).Row     'last row of column O
LastCol = Split(ws1.Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)
LastUsedCol = Split(ws1.Range("N15:" & LastCol & LastR & "").Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)

Application.ScreenUpdating = False

Set DataTable = ws1.Range("N15:" & LastCol & LastR) 'Sets the full Data Table
Set DataTable2 = ws1.Range("N15:" & LastUsedCol & LastR) 'Sets the full Data Table

  'Adjust cells with Text Only
        For Each cell In DataTable2
            If Application.WorksheetFunction.IsText(cell) = True Then
                cell.Font.Size = 16
                cell.Font.Bold = True
                cell.HorizontalAlignment = xlRight
            End If
        Next cell
        
        'Adjust the Episodes that have more than 1 at drop ("1-#")
        For Each cell In DataTable2
            If Application.WorksheetFunction.CountIf(cell, "1-*") > 0 Then
                cell.Font.Size = 11
                cell.Font.Bold = False
                cell.HorizontalAlignment = xlCenter
            End If
        Next cell
        
        'Adjust the Episodes that have numeric values only
        For Each cell In DataTable2
            If IsNumeric(cell) = True Then
                cell.Font.Size = 11
                cell.Font.Bold = False
                cell.HorizontalAlignment = xlCenter
            End If
        Next cell
        
Application.ScreenUpdating = True

    MsgBox prompt:="Table has been updated", Title:="Process Update"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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