#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Vlookup

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup

One of the "features/bugs" of excel is that you can return comments using a user
defined function.

Actually, you could use a UDF to retrieve the value and comment:

Option Explicit
Function VlookupComment(myVal As Variant, myTable As Range, _
myColumn As Long, myBoolean As Boolean) As Variant

Application.Volatile True

Dim res As Variant 'could be an error
Dim myLookupCell As Range

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If
end with

res = Application.Match(myVal, myTable.Columns(1), myBoolean)
If IsError(res) Then
VlookupComment = "Not Found"
Else
Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
VlookupComment = myLookupCell.Value
With Application.Caller
If myLookupCell.Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myLookupCell.Comment.Text
End If
End With
End If

End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=VlookupComment(a1, 'sheet2'!a:e, 5, false)

NPR_BRZ wrote:

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Vlookup

Hi Dave,
I am getting a #REF error:
the data (I placed comments on column G to test the code):
NPR001 #REF! NPR001 WK003
NPR002 NPR002 WK004
NPR003 NPR003 WK005
NPR004 NPR004 WK006
NPR005 NPR005 WK007
NPR006 NPR006 WK008
NPR007 NPR007 WK009
NPR008 #REF! NPR008 WK010
NPR009 NPR009 WK011
NPR010 NPR010 WK012
NPR011 NPR011 WK013
NPR012 NPR012 WK014
NPR013 NPR013 WK015
NPR014 NPR014 WK016
NPR015 NPR015 WK017
NPR016 NPR016 WK018

the command: =VlookupComment(B2,F:G, 2, FALSE)

the code, I copied and pasted from the message you posted.
Thanks a lot.
NPR
"Dave Peterson" wrote:

One of the "features/bugs" of excel is that you can return comments using a user
defined function.

Actually, you could use a UDF to retrieve the value and comment:

Option Explicit
Function VlookupComment(myVal As Variant, myTable As Range, _
myColumn As Long, myBoolean As Boolean) As Variant

Application.Volatile True

Dim res As Variant 'could be an error
Dim myLookupCell As Range

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If
end with

res = Application.Match(myVal, myTable.Columns(1), myBoolean)
If IsError(res) Then
VlookupComment = "Not Found"
Else
Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
VlookupComment = myLookupCell.Value
With Application.Caller
If myLookupCell.Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myLookupCell.Comment.Text
End If
End With
End If

End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=VlookupComment(a1, 'sheet2'!a:e, 5, false)

NPR_BRZ wrote:

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup

I couldn't duplicate your problem.

Are you sure you didn't put the formula in the wrong cell, then delete a row???

NPR_BRZ wrote:

Hi Dave,
I am getting a #REF error:
the data (I placed comments on column G to test the code):
NPR001 #REF! NPR001 WK003
NPR002 NPR002 WK004
NPR003 NPR003 WK005
NPR004 NPR004 WK006
NPR005 NPR005 WK007
NPR006 NPR006 WK008
NPR007 NPR007 WK009
NPR008 #REF! NPR008 WK010
NPR009 NPR009 WK011
NPR010 NPR010 WK012
NPR011 NPR011 WK013
NPR012 NPR012 WK014
NPR013 NPR013 WK015
NPR014 NPR014 WK016
NPR015 NPR015 WK017
NPR016 NPR016 WK018

the command: =VlookupComment(B2,F:G, 2, FALSE)

the code, I copied and pasted from the message you posted.
Thanks a lot.
NPR
"Dave Peterson" wrote:

One of the "features/bugs" of excel is that you can return comments using a user
defined function.

Actually, you could use a UDF to retrieve the value and comment:

Option Explicit
Function VlookupComment(myVal As Variant, myTable As Range, _
myColumn As Long, myBoolean As Boolean) As Variant

Application.Volatile True

Dim res As Variant 'could be an error
Dim myLookupCell As Range

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If
end with

res = Application.Match(myVal, myTable.Columns(1), myBoolean)
If IsError(res) Then
VlookupComment = "Not Found"
Else
Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
VlookupComment = myLookupCell.Value
With Application.Caller
If myLookupCell.Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myLookupCell.Comment.Text
End If
End With
End If

End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=VlookupComment(a1, 'sheet2'!a:e, 5, false)

NPR_BRZ wrote:

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Vlookup


Yes I am sure. The lines on the worksheet are exact the same you see below.

"Dave Peterson" wrote:

I couldn't duplicate your problem.

Are you sure you didn't put the formula in the wrong cell, then delete a row???

NPR_BRZ wrote:

Hi Dave,
I am getting a #REF error:
the data (I placed comments on column G to test the code):
NPR001 #REF! NPR001 WK003
NPR002 NPR002 WK004
NPR003 NPR003 WK005
NPR004 NPR004 WK006
NPR005 NPR005 WK007
NPR006 NPR006 WK008
NPR007 NPR007 WK009
NPR008 #REF! NPR008 WK010
NPR009 NPR009 WK011
NPR010 NPR010 WK012
NPR011 NPR011 WK013
NPR012 NPR012 WK014
NPR013 NPR013 WK015
NPR014 NPR014 WK016
NPR015 NPR015 WK017
NPR016 NPR016 WK018

the command: =VlookupComment(B2,F:G, 2, FALSE)

the code, I copied and pasted from the message you posted.
Thanks a lot.
NPR
"Dave Peterson" wrote:

One of the "features/bugs" of excel is that you can return comments using a user
defined function.

Actually, you could use a UDF to retrieve the value and comment:

Option Explicit
Function VlookupComment(myVal As Variant, myTable As Range, _
myColumn As Long, myBoolean As Boolean) As Variant

Application.Volatile True

Dim res As Variant 'could be an error
Dim myLookupCell As Range

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If
end with

res = Application.Match(myVal, myTable.Columns(1), myBoolean)
If IsError(res) Then
VlookupComment = "Not Found"
Else
Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
VlookupComment = myLookupCell.Value
With Application.Caller
If myLookupCell.Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myLookupCell.Comment.Text
End If
End With
End If

End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=VlookupComment(a1, 'sheet2'!a:e, 5, false)

NPR_BRZ wrote:

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup

Sorry,

I still couldn't duplicate the problem.

Does it work in a brand new worksheet in a brand new workbook?

NPR_BRZ wrote:

Yes I am sure. The lines on the worksheet are exact the same you see below.

"Dave Peterson" wrote:

I couldn't duplicate your problem.

Are you sure you didn't put the formula in the wrong cell, then delete a row???

NPR_BRZ wrote:

Hi Dave,
I am getting a #REF error:
the data (I placed comments on column G to test the code):
NPR001 #REF! NPR001 WK003
NPR002 NPR002 WK004
NPR003 NPR003 WK005
NPR004 NPR004 WK006
NPR005 NPR005 WK007
NPR006 NPR006 WK008
NPR007 NPR007 WK009
NPR008 #REF! NPR008 WK010
NPR009 NPR009 WK011
NPR010 NPR010 WK012
NPR011 NPR011 WK013
NPR012 NPR012 WK014
NPR013 NPR013 WK015
NPR014 NPR014 WK016
NPR015 NPR015 WK017
NPR016 NPR016 WK018

the command: =VlookupComment(B2,F:G, 2, FALSE)

the code, I copied and pasted from the message you posted.
Thanks a lot.
NPR
"Dave Peterson" wrote:

One of the "features/bugs" of excel is that you can return comments using a user
defined function.

Actually, you could use a UDF to retrieve the value and comment:

Option Explicit
Function VlookupComment(myVal As Variant, myTable As Range, _
myColumn As Long, myBoolean As Boolean) As Variant

Application.Volatile True

Dim res As Variant 'could be an error
Dim myLookupCell As Range

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If
end with

res = Application.Match(myVal, myTable.Columns(1), myBoolean)
If IsError(res) Then
VlookupComment = "Not Found"
Else
Set myLookupCell = myTable.Columns(myColumn).Cells(1)(res)
VlookupComment = myLookupCell.Value
With Application.Caller
If myLookupCell.Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myLookupCell.Comment.Text
End If
End With
End If

End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=VlookupComment(a1, 'sheet2'!a:e, 5, false)

NPR_BRZ wrote:

Is it possible to copy the comment on the cell together with the information
when executing a vlookup?

thanks.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 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 -=VLOOKUP(F9,LookUp1!$A$2:$B$1504,2,FALSE) MikeR-Oz New Users to Excel 1 March 22nd 06 09:01 AM
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 11:29 AM.

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"