Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Can I do conditional formula based on data in cell comment?

We have 2 add-in SW vendors which return values with comments to a cell. I
want to check the vendor ID in cell comment to determine if I need to do a
calculation on value. Is that possible via a simple formula or is a macro or
something more complicated required? Is it even possible?

We are using MS Excel 2003.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 27
Default Can I do conditional formula based on data in cell comment?

Hi

You would need to refer to the cell in VBA

EG....

if Range("A1").comment.text = "Hello" Then
MsgBox "Say Hello"
End If

I don't think you can refer to a comment in a formula without VB

Steve

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Can I do conditional formula based on data in cell comment?

Thanks, I've been reviewing the "Programming" section of Excel. It looks like
I'll have to teach myself VBA!


"SIR Knight" wrote:

Hi

You would need to refer to the cell in VBA

EG....

if Range("A1").comment.text = "Hello" Then
MsgBox "Say Hello"
End If

I don't think you can refer to a comment in a formula without VB

Steve


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default Can I do conditional formula based on data in cell comment?

One way to learn how VBA refers to cell comments is to record a macro in
which you enter a comment in a cell, and then look at the VBA code that Excel
automatically returns.

That doesn't mean you'll have the precise syntax for what you're looking to
do, but it means you will have some idea of what code you're looking for.

Hope that helps/

"da@DRI" wrote:

Thanks, I've been reviewing the "Programming" section of Excel. It looks like
I'll have to teach myself VBA!


"SIR Knight" wrote:

Hi

You would need to refer to the cell in VBA

EG....

if Range("A1").comment.text = "Hello" Then
MsgBox "Say Hello"
End If

I don't think you can refer to a comment in a formula without VB

Steve


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Can I do conditional formula based on data in cell comment?

I don't know of any way to reference the .Comment in another cell with a
formula, so either a 'pure' VBA macro solution is needed, or you could look
at this hybrid solution.

I've used the worksheet _SelectionChange event to try to determine if you've
clicked on one of your cells that has the comment with information in it. If
that has happened (if the cell has a comment), the text content of the
comment is placed into another cell on the same row.

Then back in the place where you may or may not want to do your math, you
can now use an IF() statement to examine the cell where the text has
magically appeared to see if you want to do the math or not.

This code presumes the cells "of interest" are in column A, and that we can
use column H to display the text of a comment.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iSect As Range
Dim myVar As Variant

'did user choose cell in column A?
Set iSect = Application.Intersect(Range(Target.Address), Range("A:A"))
If iSect Is Nothing Then
Exit Sub ' no, do nothing
End If
'user selected cell in column of interest (A)
'check if cell has comment
Application.EnableEvents = False
If Range(Target.Address).Comment Is Nothing Then
'no comment, get out
Application.EnableEvents = True
Exit Sub
End If
'if any error occurs from here on, just ignore it without action
On Error GoTo ExitChange
'we will set value of another cell to contain contents of
'the comment, assume on the same row, 7 columns to right (column I)
myVar = Trim(Target.Comment.Text) ' remove leading/trailing white space
'if someone hit [Enter] at end, remove that also
Do While InStr(myVar, Chr$(10))
myVar = Replace(myVar, Chr$(10), "")
Loop
Target.Offset(0, 7) = myVar
iSect.Select
ExitChange:
If Err < 0 Then
Err.Clear
On Error GoTo 0
End If
Application.EnableEvents = True

End Sub

So now, you could enter a formula like this in a cell to actually do the
math, or not, based on contents of the comment - this was from B3 on my test
sheet:
=IF(H3="a041b5","Do The Math",0)

You can upload an Excel 2003 file with all of this in it from:
http://www.jlathamsite.com/uploads/for_da_at_dri.xls
and if you need help figuring out how to get into the area where you place
code into a Worksheet's event, this page should help:
http://www.jlathamsite.com/Teach/WorksheetCode.htm


"da@DRI" wrote:

We have 2 add-in SW vendors which return values with comments to a cell. I
want to check the vendor ID in cell comment to determine if I need to do a
calculation on value. Is that possible via a simple formula or is a macro or
something more complicated required? Is it even possible?

We are using MS Excel 2003.

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
Lookup Data in two seperate Spreadsheets Padraig Excel Worksheet Functions 6 June 28th 06 03:05 PM
Conditional Formatting if cell content is a formula oldsambvca Excel Worksheet Functions 2 June 6th 06 10:24 PM
conditional cell format based on cell in same row, previous column tamiluchi Excel Worksheet Functions 7 May 3rd 06 04:11 PM
enhanced conditional formatting Stuart Excel Discussion (Misc queries) 13 November 13th 05 07:20 PM
inserting data from a row to a cell, when the row number is specified by a formula in a cell [email protected] New Users to Excel 2 January 6th 05 07:18 AM


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