#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default VLOOKUP Question

Access 2003 - not sure how do write the correct VBA code to accomplish this.
I have a small macro with hard-coded vendor numbers in it that if they are
found, turns the excel line either red or green. But the problem is that
these vendor numbers may change from time to time. Have a worksheet where
these test vendors are stored and want to access this worksheet to used these
instead of relying on the hard-coding.

He is my hard-coding macro:
Sub ColorRich()

x = ActiveCell.Row

Do While Cells(x, 3).Value < ""
If (Cells(x, 3).Value = 2142) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 4
ElseIf (Cells(x, 3).Value = 2852) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 4
ElseIf (Cells(x, 3).Value = 4761) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 4
ElseIf (Cells(x, 3).Value = 6587) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 4
ElseIf (Cells(x, 3).Value = 2399) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 3
ElseIf (Cells(x, 3).Value = 9441) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 3
ElseIf (Cells(x, 3).Value = 10319) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 3
ElseIf (Cells(x, 3).Value = 12923) Then
Cells(x, 3).EntireRow.Interior.ColorIndex = 3
End If

x = x + 1

Loop

End Sub

And here is a snapshot of my test vendor file:

Column A
Vendor #:
2142
2399
2852
4761
6587
9441
10319
12923

The file I would run this macro against may have anywhere from 1 - x number
of lines so I would like the new macro to run until a blank line is found.

I am very new to VBA and tried to look thru the threads but couldn't put
enought together to figure this out. Thanks in advance for all your help and
suggestions.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default VLOOKUP Question

Forgot to mention - there is a second column in the Status report that will
determine if red or green - is '*' then green else red.

Column A Column B
Vendor #: Email Vendor
2142 *
2399
2852 *
4761 *
6587 *
9441
10319
12923

  #3   Report Post  
Posted to microsoft.public.excel.misc
bj bj is offline
external usenet poster
 
Posts: 1,397
Default VLOOKUP Question

conditional formatting will do this without a macro
select all
format as red
<format<conditional format
change "cell value is" to "equation is"
=vlookup(C1,venderfile!A:B,2,0)="*"
set format as green.

using appropriate name for vendefile


"Rich K." wrote:

Forgot to mention - there is a second column in the Status report that will
determine if red or green - is '*' then green else red.

Column A Column B
Vendor #: Email Vendor
2142 *
2399
2852 *
4761 *
6587 *
9441
10319
12923

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default VLOOKUP Question

Not sure I fully understand and possible I did not explain clearly. Not all
entries will be red or green. By default, all are not filled. Only ones in
the status report will be green (with '*') or red (without '*'). Will try to
work with what you gave me.

Normally don't use conditional formatting because I do work in blank
workbook and copy/paste final results into shared final workbook. But...
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default VLOOKUP Question

Tried working with Conditional Formating but when I clicked ok, got error
message "You may not use references to other worksheets or workbooks for
conditional formatting criteria'.

Format of expression was:

=vlookup(C2,'[EDI Status Report.xls]Test Vendors'!A:B,2,0)="*"

where EDI Status Report.xls is the workbook and Test Vendors is the
worksheet within that workbook.

Any other ideas? Or am I missing something?


  #6   Report Post  
Posted to microsoft.public.excel.misc
bj bj is offline
external usenet poster
 
Posts: 1,397
Default VLOOKUP Question

forgot about that, sorry
to not use conditional, try

Sub colorrisch2()
Sheets("vender").Activate
n = Application.WorksheetFunction.Count(Columns(1))
Dim ven(n, 2)
For i = 1 To n
ven(i, 1) = Cells(i, 1)
ven(i, 2) = Cells(i, 2)
Next i
Sheets("data").Activate
x = 1
10 If Cells(x, 3) = "" Then GoTo 99
For i = 1 To n
If Cells(x, 3) = ven(i, 1) Then Cells(x,
3).EntireRow.Interior.ColorIndex = 3
If Cells(x, 3) = ven(i, 1) And ven(i, 2) = "*" Then Cells(x,
3).EntireRow.Interior.ColorIndex = 4
Next i
x = x + 1
GoTo 10
99
End Sub

"Rich K." wrote:

Tried working with Conditional Formating but when I clicked ok, got error
message "You may not use references to other worksheets or workbooks for
conditional formatting criteria'.

Format of expression was:

=vlookup(C2,'[EDI Status Report.xls]Test Vendors'!A:B,2,0)="*"

where EDI Status Report.xls is the workbook and Test Vendors is the
worksheet within that workbook.

Any other ideas? Or am I missing something?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
=vlookup question scott Excel Discussion (Misc queries) 0 June 8th 06 06:14 PM
vlookup question Brian Excel Discussion (Misc queries) 1 April 18th 06 03:31 AM
VLOOKUP Question mllestecchino Excel Worksheet Functions 4 April 6th 06 08:53 PM
Vlookup Question carl Excel Worksheet Functions 1 February 21st 06 05:50 PM
vlookup question Greegan Excel Worksheet Functions 3 December 20th 05 04:00 AM


All times are GMT +1. The time now is 04:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"