ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to run a macro only if a cell contains a certain value (https://www.excelbanter.com/excel-programming/288434-how-run-macro-only-if-cell-contains-certain-value.html)

KJ[_2_]

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!!!!!

Bob Phillips[_6_]

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!!!!!




mudraker[_109_]

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/


Bob Phillips[_6_]

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



Beto[_3_]

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.


KJ[_2_]

how to run a macro only if a cell contains a certain value
 
THANKS! YOU WERE RIGHT


All times are GMT +1. The time now is 01:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com