Solved

VBA - Finad Names, replace Value & Format

Posted on 2011-09-19
3
303 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:codyvance1
[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 500 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:codyvance1
ID: 36561348
Awesome!  Works perfectly.   Thanks for Speedy Response!

Cody-
0
 

Author Comment

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

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

Featured Post

Industry Leaders: 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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

690 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