Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Comparing cells?

Hello All,
I am working on some excel VBA code and I am a little - ok - a lot stuck on
a procedure I am trying to create.

I have 2 sheets in the workbook one called "produce code" and one called
"produce name"

On the produce code sheet are drop down boxes in each cell of column A that
contain the produce code, column B is blank. When a user selects a a code I
want to populate the cell beside it (column B) with the name located in the
worksheet "produce name"

The second worksheet ("produce name") has all the codes and names i.e.

Column A Column B
1 Banana
2 Apple
3 Orange

So when the user selects 1 in column A of worksheet "produce code" I am
trying to populate column B with "Banana". I can do this using vbLookup but
I want to do this using vba code.

My thought is putting column A when selected into a variable then looping
through Column A of the second worksheet to find a match and selecting the
value of the cell beside it.

Can anyone please help.

Thank you so much for your time

Dan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Comparing cells?


To do this in VBA, you can call the Excel VLookup function from withi
VBA

Assume A1 has your list box,
the cell link is B1
you have a range with your lookup table 1 banana, 2 apples etc

the this code will give you what you want

Sub test()
Dim myRange As Range
y = Range("B1").Value
Set myRange = Range("Table")
X = Application.WorksheetFunction.VLookup(y, myRange, 2)
End Sub

Regards

Mat

--
Mallyca
-----------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...fo&userid=3551
View this thread: http://www.excelforum.com/showthread.php?threadid=56178

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
Comparing Cells basic Excel Discussion (Misc queries) 1 August 20th 09 08:37 PM
Comparing cells when they are not exactly the same Garry Excel Discussion (Misc queries) 2 April 2nd 07 10:26 AM
Comparing two cells Mandeep Dhami Excel Discussion (Misc queries) 2 March 30th 06 07:30 AM
Comparing Cells EXCEL101 Excel Worksheet Functions 3 August 30th 05 12:51 AM
Need a bit of help on comparing cells ste mac Excel Programming 2 March 16th 05 10:42 AM


All times are GMT +1. The time now is 06:17 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"