Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default VBA using VLookUp

I have two workbooks open: book2.xls and Dept_IDs.xls

I want to use VBA to determine if a value in cell A7 of Sheet1 of book2.xls
needs to have its cell colored based on the 3rd column of data in a range
named: Dept_ID_T in the workbook: Dept_IDs.

IE, if the
VLookUp([book2.xls]Sheet1!A7,[Dept_IDs_0911.xls]Dept_ID_T_WS!Dept_ID_T,3,FALSE) = "410-50", then I want to color cell A7 a light yellow.

What's the VBA to determine if the vLookUp would return the value "410-50"?

Your help will be appreciated.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VBA using VLookUp

Try this. I used FIND instead of VLOOKUP. I also set variables for each
item to make it easier to understand the code and to debug the code.

Set bk = thisworkbook
Set sht = bk.sheets("Sheet1")

Set Deptbk = workbooks("Dept_IDs_0911.xls")
set DeptSht = Deptbk.sheets("Dept_ID_T_WS")

LookupValue = sht.range("A7")
set c = DeptSht.Range(Dept_ID_T).find(what:=LookupValue, _
lookin:=xlvalues,lookat:=xlwhole)
if c is nothing then
msgbox("did not find : " & Lookupvalue)
else
'get column 3 of table
Col_3 = c.offset(0,2)
if Col_3.value = "410-50" then
sht.range("A7").interior.colorindex = 6
end if
end if


"ND Pard" wrote:

I have two workbooks open: book2.xls and Dept_IDs.xls

I want to use VBA to determine if a value in cell A7 of Sheet1 of book2.xls
needs to have its cell colored based on the 3rd column of data in a range
named: Dept_ID_T in the workbook: Dept_IDs.

IE, if the
VLookUp([book2.xls]Sheet1!A7,[Dept_IDs_0911.xls]Dept_ID_T_WS!Dept_ID_T,3,FALSE) = "410-50", then I want to color cell A7 a light yellow.

What's the VBA to determine if the vLookUp would return the value "410-50"?

Your help will be appreciated.

Thanks.

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 - Does the VLookUp return the exact information? Cpviv Excel Worksheet Functions 2 October 28th 08 09:57 AM
using a vlookup to enter text into rows beneath the vlookup cell Roger on Excel Excel Programming 1 November 29th 07 12:09 PM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Which is faster: VLOOKUP-worksheet or VB-array VLOOKUP? erikhs[_20_] Excel Programming 1 August 6th 06 06:18 PM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 12:18 AM.

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

About Us

"It's about Microsoft Excel"