Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how to run a macro only if a cell contains a certain value

I have written a macro to divide a large spreadsheet into 5 smaller ones based on single character in one of the columns. One of the letters only appears on every other report which causes the macro to crash if it doesn't find the letter.
Is there any way to have Macro5 run only if the letter K is found in a cell in a specified column? I have tried and tried but cannot figure out how to get the macro to read a character in the cell - only a number.

Any help would be greatly appreciated!!!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how to run a macro only if a cell contains a certain value

Testing a letter is simple, something like

If Range("A1").Value = "K" Then
...

What code are you trying?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"KJ" wrote in message
...
I have written a macro to divide a large spreadsheet into 5 smaller ones

based on single character in one of the columns. One of the letters only
appears on every other report which causes the macro to crash if it doesn't
find the letter.
Is there any way to have Macro5 run only if the letter K is found in a

cell in a specified column? I have tried and tried but cannot figure out
how to get the macro to read a character in the cell - only a number.

Any help would be greatly appreciated!!!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to run a macro only if a cell contains a certain value

One way

Place this code at the start of the Macro


Sub MyMacro()
'dim Statements

If LCase(Range("a1").Value) < "K" Then
Exit Sub
End If

'your code here

End Sub


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how to run a macro only if a cell contains a certain value


If LCase(Range("a1").Value) < "K" Then
Exit Sub
End If


Might not get a lot happening here<VBG


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default how to run a macro only if a cell contains a certain value

mudraker < wrote:

One way

Place this code at the start of the Macro


Sub MyMacro()
'dim Statements

If LCase(Range("a1").Value) < "K" Then
Exit Sub
End If

'your code here

End Sub


Shouldn't it be UCase instead of LCase? otherwise the macro never continues.

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how to run a macro only if a cell contains a certain value

THANKS! YOU WERE RIGHT
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
'IF' Macro to insert cell contents to alternate cell if cell not e Gryndar Excel Worksheet Functions 6 December 20th 08 05:02 PM
Macro to Insert Current Date into cell - Macro to "Save As" Guy[_2_] Excel Worksheet Functions 4 December 12th 08 08:20 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Excel Programming 1 July 8th 03 03:03 PM


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