Macros how to put multiple value in this code: if oCell.value = 5 then

if oCell.value = 5 then

I want to put more different value instead only one value “5” in above code,
I tried use “or” / " ", and , , but not working well,
if oCell.value = 5 or 6 or 9 or 11 then
also, I found it macros doesn’t recognize value like this: 5-20220901,
I mean the sign: -
it don’t recongnize -

Hallo
With the hints given by @JohnSUN in your other thread, you would have finished, without any stupid macro-code.
5-20220901 isnt a .Value … its a …String.

Thanks, JohnSUN’s advice is not suitable for mine, as I have thousands sn need click,
string? I tried “12-20220901”, but it doesn’t work,

There is also the property oCell.String you can use.
And if you need initial number from string that starts with number, you can use CLng.
msgbox CLng("5-20220901") 'show the number 5

1 Like

Thank you so much, I will try it and get back to you! :grinning:

Brilliant, yes, oCell.String make it works!
I need 2000 string checked, I tried the code like this:
oCell.String=“105-20220901” , “108-20220901”
but it doesn’t works

Via if and OR

	dim a&
	a=CLng(oCell.String)
	if a=5 OR a=6 OR a=9 OR a=15 then
		msgbox "OK"
	else
		msgbox "other number: " & a
	end if

Via Select case

	dim a&
	a=CLng(oCell.String)
	select case a
	case 5, 6, 9, 11
		msgbox "OK"
	case else
		msgbox "other number: " & a
	end select

It will be faster via .getDataArray() than via oCell.String.

I like to believe you already found the A. Pitonyak Macro Book and Macro Reference Cards in LibreOffice documentation; also the LibreOffice Help wist examples for macros; and also the LibreOffice Wiki for macros; and also the extensions MRI or XRay :-).

2 Likes

@alan20alan:
Still true: If you have thousands of strings to check for, you either need to type them one by one as literal strings, or to find a simpler way to describe them all based on a common and exclusive syntactical scheme or to generate them all by code based on a generative scheme, or to invent a new way to get them in a bag.
Once you decided -regarding realistic limitations- which one of these ways you want to go, we can start to discuss the details and to suggest an actual solution.
The question “…how to put multiple value in this code: if oCell.value = 5 then…” only has one answer: No realistic way for thousands of alternatives.
The question “How to decide if a string is starting with an integer followed by one of the separators “-#%” and then by one of the strings 20220901 or 90991224 ?” has a very simple answer: Use the regular expression
[\-+]?\d+[\-#%](20220901|90991224)
If you then aren’t sufficiently experienced with the usage of RegEx we can help.
If you refuse to learn the basics first, but expect us to be sorcerers knowing a spell for every miracle to happen, you (and we) will fail.
BTW: Dont tell me 20220901 is not a date (it is by ISO standards), but tell me what the second part of your “sn” actually is, and how the cases needing to be treated are distinguished from the others.
Otherwise choose the type alternative, type all the special “sn” strings into the cells of an empty column, and we can tell you how to find the rows where such a value is present in a different column. The process may take time because it basically requires n*m comparisons for n rows needing a test with m alternatively accepted strings. n = 100000, m = 1000 makes 100 million comparisons, you know.
Aha! But if you can allow for sorting the data and for sorting the special “sn” strings as well, you can get highly improved efficiency. We know a few tricks after all.

1 Like

t85284.ods (26.9 KB)

@Villeroy It was a good try, but in vain - this won’t be accepted as an answer. Do you know why?

First, in your example, there is not a single cell with the - sign.

Second, it’s not a macro. :grinning_face_with_smiling_eyes:

All joking aside:
The original question (“other thread”) was
“I want to delete some rows with about 1000 different sn like{emphasis by commenter}: 1-20220901, 15-20220901, 20-20220920…”
But we didn’t get a clue what like meant in the context.
Concerning the second part: Is it any date in september 2022 given in IS8601 not-extended is it any sequence of exactly eight digits or is it any one of the numbers listed in ColumnAA of the sheet? Concerning the part before the dash we also need to guess.
I don’t want to exclude that a macro could be useful in solving the actual task (CF Recurse recorded Macro? also about removing content based on findings), but the
IF StringExpression1=StringExpression2 Then ...
is certainly not a reasonable starting point.
As so often: The questioner needs to be more precise about what he actually wants to achieve. The good old SimplifiedExample.ods with a sheet Have and a sheet Want completed by some explanations “inline” might help.

1 Like

In any case, for any criterion - a mask of a value, a list of excluded values, calculated by date - the task in any case comes down not to “deleting rows”, but to “filtering data”. The starting question has already been formulated erroneously. We were called to solve the “XY-problem”, in the middle of the way… of the wrong way… as always…

2 Likes

t85284_2.ods (37.6 KB)

1 Like

Resolving the steps of my little program:
t85284_3.ods (81.5 KB)

2 Likes

Thanks a lot, I will try it.

Hi,

You can split your string in various columns by a macro or by theses commands :
left(cell,nb) or right(cell,nb) and combined : left(right(cell,nb),nb)
That’s an easy way to comput large values.

Regards