Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 727975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:37:42+00:00 2026-05-14T06:37:42+00:00

Here’s what I need to do: 1) Loop through every cell in a worksheet

  • 0

Here’s what I need to do:

1) Loop through every cell in a worksheet
2) Make formatting changes (bold, etc) to fields relative to each field based on the value

What I mean is that if a field has a value of “foo”, I want to make the field that is (-1, -3) from it bold, etc. I tried to do this with the following script with no luck.

Thanks
Johnny

Pseudo Code to Explain:

For Each Cell in WorkSheet
    If Value of Cell is 'Subtotal'
        Make the cell 2 cells to the left and 1 cell up from here bold and underlined
    End If
End ForEach

The Failed Macro (I don’t really know VB at all):

Sub Macro2()
'
'
'
Dim rnArea As Range
Dim rnCell As Range

Set rnArea = Range("J1:J2000")

    For Each rnCell In rnArea
        With rnCell
            If Not IsError(rnCell.Value) Then
                Select Case .Value
                    Case "000 Total"
                        ActiveCell.Offset(-1, -3).Select
                        ActiveCell.Font.Underline = XlUnderlineStyle.xlUnderlineStyleSingleAccounting
                End Select
            End If
        End With
    Next
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:37:43+00:00Added an answer on May 14, 2026 at 6:37 am
    Option Explicit
    
    Private Sub macro2()
        Dim rnArea As Range
        Dim rnCell As Range
    
        ' you might need to change the range to the cells/column you want to format e. g. "G1:G2000" '
        Set rnArea = Range("J1:J2000")
    
        For Each rnCell In rnArea
            With rnCell
                If isBold(.Offset(1, 3).Value) Then
                    .Font.Bold = True
                End If
                If isUnderlined(.Offset(1, 3).Value) Then
                    'maybe you want this: .Font.Underline = xlUnderlineStyleSingle '
                    .Font.Underline = xlUnderlineStyleSingleAccounting
                End If
            End With
        Next
    End Sub
    
    Private Function isBold(cellValue As Variant) As Boolean
        Dim myList() As Variant
        Dim listCount As Integer
        Dim i As Integer
    
        myList = Array("Totals", "FooTotal", "SpamTotal")
        listCount = 3
    
        isBold = False
        For i = 0 To listCount - 1
            If cellValue = myList(i) Then
                isBold = True
                Exit Function
            End If
        Next i
    End Function
    
    Private Function isUnderlined(cellValue As Variant) As Boolean
        Dim myList() As Variant
        Dim listCount As Integer
        Dim i As Integer
    
        myList = Array("FooTotal", "SpamTotal")
        listCount = 2
    
        isUnderlined = False
        For i = 0 To listCount - 1
            If cellValue = myList(i) Then
                isUnderlined = True
                Exit Function
            End If
        Next i
    End Function
    

    I added two functions but it should have also worked with an extensive if / else if / else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.