?
Solved

VBA - Finad Names, replace Value & Format

Posted on 2011-09-19
3
Medium Priority
?
305 Views
Last Modified: 2012-08-13
Hi Experts,

I need some help with the attached Excel file.  You can see the code I have for FindNames.  This should look at each name in Column G in "Macro Completed" sheet, and if that name is listed in "Names" sheet, it should replace value in Column E of "Macro Completed" with value next to name on Names Sheet (ST Name) as well as perform some formatting, etc.  Right now it only does it for the first instance of each name found.  I need it to work for entire sheet.

THanks!
Cody-
Macro-Sample.xls
0
Comment
Question by:Cody Vance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 2000 total points
ID: 36561336
Cody - see if this works:
Public Sub FindNames()

Dim wkb As Workbook
Dim dataSht As Worksheet
Dim namesSht As Worksheet
Dim rng As Range
Dim fRange As Range
Dim myName As Range
Dim s As String

Set wkb = ThisWorkbook
Set namesSht = wkb.Sheets("Names")
Set dataSht = wkb.Sheets("Macro Completed")

For Each myName In namesSht.Range("A2", namesSht.Range("A" & namesSht.Rows.Count).End(xlUp)) 'First name to search for in Column A
    If myName <> "" Then
        Set fRange = dataSht.Range("G:G").Find(What:=myName.Value, LookIn:=xlFormulas, LookAt:=xlWhole) 'Search in Column G for "Name" from column A
        If Not fRange Is Nothing Then 'Name found!
            'myName.Font.Bold = True 'Make Column A name Bold as in example code
            'myName.Interior.ColorIndex = 15 'Color Code Column A
            s = fRange.Address
            Do
                fRange.Offset(0, -6).Font.Bold = True
                fRange.Offset(0, -6).Interior.ColorIndex = 15
                fRange.Offset(0, -2).Value = myName.Offset(0, 1).Value 'set Column E same row = column B from myName match
                fRange.Offset(0, -2).Interior.ColorIndex = 15 'color code Column E
                fRange.Offset(0, -1).Value = "Please Send to Adam Farer for check in." 'alert message Column F
                fRange.Offset(0, -1).Font.Bold = True 'Bold Column F as in example code
                Set fRange = dataSht.Cells.FindNext(fRange)
            Loop While fRange.Address <> s
        End If
    End If
    s = ""
Next myName

End Sub

Open in new window

0
 

Author Comment

by:Cody Vance
ID: 36561348
Awesome!  Works perfectly.   Thanks for Speedy Response!

Cody-
0
 

Author Comment

by:Cody Vance
ID: 36561438
Guess I jumped the gun, getting Application object defined error on

fRange.Offset(0, -6).Font.Bold = True
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question