Solved

VBA - Finad Names, replace Value & Format

Posted on 2011-09-19
3
302 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

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

696 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