Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Comments - populate using vlookup

I have a column which contains a list of chemicals.

I use vlookup to get data for the chemicals such as density, flash point and
boiling point etc.

What i would like is for a comment box to become available for each
chemical, containing the vlookup data so that the chemical properties are
readily available when the curser goes over each chemical.

Is this possible and would it be possible for the comment box only to become
available if a chemical is actually in the column?

Can anyone help?

Thanks,

Roger
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Comments - populate using vlookup

Using something like this should get you started. I made some assumptions
on where the vlookup was located and the column you wanted to modify. If a
comment already exists, I didn't account for that. Right click on the
worksheet tab to View Code and paste this in the worksheet where you'll be
making changes.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim myLookupRange As Range
Dim myVal As Variant

'This is the column that you want to add a value
Set myRange = Me.Range("B:B")

'Exits if more than one cell is modified
If Target.Count < 1 Then Exit Sub

'Exits if target doesn't intersect with range
If Intersect(Target, myRange) Is Nothing Then Exit Sub

'I've assumed that the lookup range is a workbook level range
'If you need more help with this, come back
'Search for Dynamic range and OFFSET
Set myLookupRange = Range("LookupRange")
myVal = Null
On Error Resume Next
myVal = WorksheetFunction.VLookup(Target.Value, myLookupRange, 1, False)
On Error GoTo 0
If myVal = Null Then
MsgBox ("No lookup value found in table")
Else
msg = "Specific Gravity: " & WorksheetFunction.VLookup(Target.Value,
myLookupRange, 2, False)
msg = msg & Chr(10) & "Density: " &
WorksheetFunction.VLookup(Target.Value, myLookupRange, 3, False)
msg = msg & Chr(10) & "Flash Point: " &
WorksheetFunction.VLookup(Target.Value, myLookupRange, 4, False)
With Target
.AddComment (msg)
End With
End If

End Sub
--
HTH,
Barb Reinhardt



"Roger on Excel" wrote:

I have a column which contains a list of chemicals.

I use vlookup to get data for the chemicals such as density, flash point and
boiling point etc.

What i would like is for a comment box to become available for each
chemical, containing the vlookup data so that the chemical properties are
readily available when the curser goes over each chemical.

Is this possible and would it be possible for the comment box only to become
available if a chemical is actually in the column?

Can anyone help?

Thanks,

Roger

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Comments - populate using vlookup

Hi Barb,

Thanks for helping me again.

Im using the code you gave me, but i have an error message

"Method 'Range of object'_Worksheet' failed"

It has a problem on the following line. My data table for vlookup is a named
range called "Materials" which is on a sheet called Chemicals and has all the
data in it, so i substituted that name into the code - hence :

Set myLookupRange = Range("Materials")

What do you think Barb?

Roger



"Barb Reinhardt" wrote:

Using something like this should get you started. I made some assumptions
on where the vlookup was located and the column you wanted to modify. If a
comment already exists, I didn't account for that. Right click on the
worksheet tab to View Code and paste this in the worksheet where you'll be
making changes.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim myLookupRange As Range
Dim myVal As Variant

'This is the column that you want to add a value
Set myRange = Me.Range("B:B")

'Exits if more than one cell is modified
If Target.Count < 1 Then Exit Sub

'Exits if target doesn't intersect with range
If Intersect(Target, myRange) Is Nothing Then Exit Sub

'I've assumed that the lookup range is a workbook level range
'If you need more help with this, come back
'Search for Dynamic range and OFFSET
Set myLookupRange = Range("LookupRange")
myVal = Null
On Error Resume Next
myVal = WorksheetFunction.VLookup(Target.Value, myLookupRange, 1, False)
On Error GoTo 0
If myVal = Null Then
MsgBox ("No lookup value found in table")
Else
msg = "Specific Gravity: " & WorksheetFunction.VLookup(Target.Value,
myLookupRange, 2, False)
msg = msg & Chr(10) & "Density: " &
WorksheetFunction.VLookup(Target.Value, myLookupRange, 3, False)
msg = msg & Chr(10) & "Flash Point: " &
WorksheetFunction.VLookup(Target.Value, myLookupRange, 4, False)
With Target
.AddComment (msg)
End With
End If

End Sub
--
HTH,
Barb Reinhardt



"Roger on Excel" wrote:

I have a column which contains a list of chemicals.

I use vlookup to get data for the chemicals such as density, flash point and
boiling point etc.

What i would like is for a comment box to become available for each
chemical, containing the vlookup data so that the chemical properties are
readily available when the curser goes over each chemical.

Is this possible and would it be possible for the comment box only to become
available if a chemical is actually in the column?

Can anyone help?

Thanks,

Roger

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 to populate drop-down Isitfridayyet Excel Discussion (Misc queries) 0 June 2nd 08 04:32 PM
Vlookup? populate 3 columns of data when match a common value, UMPhy Tom Excel Worksheet Functions 1 March 13th 08 07:26 PM
vlookup comments Ann Excel Discussion (Misc queries) 0 March 8th 07 11:36 PM
cell comments in a vlookup table crusty53 New Users to Excel 0 August 24th 06 05:22 AM
Macro to Add Comments with vlookup AllenWatts Excel Programming 2 May 10th 06 07:43 PM


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