Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to test cell contents in a macro?


I'm using MS Excel 2000, and I want to write a macro that tests cell
contents. Unfortunately, after a couple hours of looking at help files
(MS Visual Basic 6.0), I have found no method to do so.

My code concept is
If Cellcontents(activecell) = "dog" then
DoSomething
EndIf

This used to be so easy in Lotus 1-2-3...haha, way back in the
pre-Win95 era! Can someone point me on the right track?


--
JennyGard
------------------------------------------------------------------------
JennyGard's Profile: http://www.excelforum.com/member.php...o&userid=31803
View this thread: http://www.excelforum.com/showthread...hreadid=515272

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to test cell contents in a macro?

Hi Jenny,

Try:

If Range("A1").Value = "dog" Then
'Your code
Else
'Do something else
End If

Or, if case is unimportant:

If LCase(Range(2A1").Value) = "dog" Then


---
Regards,
Norman



"JennyGard" wrote
in message ...

I'm using MS Excel 2000, and I want to write a macro that tests cell
contents. Unfortunately, after a couple hours of looking at help files
(MS Visual Basic 6.0), I have found no method to do so.

My code concept is
If Cellcontents(activecell) = "dog" then
DoSomething
EndIf

This used to be so easy in Lotus 1-2-3...haha, way back in the
pre-Win95 era! Can someone point me on the right track?


--
JennyGard
------------------------------------------------------------------------
JennyGard's Profile:
http://www.excelforum.com/member.php...o&userid=31803
View this thread: http://www.excelforum.com/showthread...hreadid=515272



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to test cell contents in a macro?

Hi Jenny.

There is a typo:

If LCase(Range(2A1").Value) = "dog" Then


should read

If LCase(Range("A1").Value) = "dog" Then

(2 == ")

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Jenny,

Try:

If Range("A1").Value = "dog" Then
'Your code
Else
'Do something else
End If

Or, if case is unimportant:

If LCase(Range(2A1").Value) = "dog" Then


---
Regards,
Norman



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to test cell contents in a macro?


Thanks, guys!
Both methods worked, and they were easy...just as I suspected...but I
just couldn't quite figure it out for myself. The MS VB help files
certainly do not seem geared for beginners. Is there a good online
introduction to Excel macro programming?


--
JennyGard
------------------------------------------------------------------------
JennyGard's Profile: http://www.excelforum.com/member.php...o&userid=31803
View this thread: http://www.excelforum.com/showthread...hreadid=515272

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default How to test cell contents in a macro?

If ActiveCell.Value = "dog" Then...

You can even omit the .Value as it is the default property of the
ActiveCell object: If ActiveCell = "dog" Then...


JennyGard wrote:
I'm using MS Excel 2000, and I want to write a macro that tests cell
contents. Unfortunately, after a couple hours of looking at help files
(MS Visual Basic 6.0), I have found no method to do so.

My code concept is
If Cellcontents(activecell) = "dog" then
DoSomething
EndIf

This used to be so easy in Lotus 1-2-3...haha, way back in the
pre-Win95 era! Can someone point me on the right track?


--
JennyGard
------------------------------------------------------------------------
JennyGard's Profile: http://www.excelforum.com/member.php...o&userid=31803
View this thread: http://www.excelforum.com/showthread...hreadid=515272




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
Macro to transfer contents of 'Selected' cell to alternate cell. Gryndar Excel Worksheet Functions 7 December 20th 08 09:58 PM
Is there a logical test for a cell's format instead of contents Bruce Excel Worksheet Functions 3 November 17th 05 01:40 AM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM
Test is cell contents are a URL Jim[_55_] Excel Programming 1 January 18th 05 05:46 PM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM


All times are GMT +1. The time now is 02:58 PM.

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"