Query - Formula (Test for string)
Sorry, but I'm confused...
This is what your code is doing:
1) Defines the constant "Prefix" to equal: "CD-"
2) Checks if the left 3 chars of the string "B4" = "CD-"
(which it never will, of course. Did you want it to check cell B4?)
2a) But, if it does....then select cell B4
2b) Next, using the active cell (which can only be B4)...
Prepend the Prefix to its value.
3) Otherwise, do nothing
What did you intend the code to do?
--------------------------
Regards,
Ron (XL2003, Win XP)
Microsoft MVP (Excel)
wrote in message
ups.com...
Hi,
Can someone help with the following @ all. I've created the following
VBA which works as expected the first time, however I only want it to
check for the value once, whereas this will add in the prefix more
than once when I run it?
e.g. this is meant to check B4, if this contains CD- don't do anything
if it doesn't add it in.
Any suggestions?
Cheers, Al.
Sub Prefix()
Const Prefix = "CD-"
If Left("B4", 3) = "CD-" Then
Range("B4").Select
ActiveCell.Value = Prefix & ActiveCell.Value
Else
End If
End Sub
|