Can someone interpret this line of code please?

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I have this line of code that seems to work in some modules but not in others. Can someone please tell me (in plain English) what the "-1" means in this line of code?

sDates = Right(daterangeballpractice, Application.WorksheetFunction.Find(" ", daterangeballpractice) - 1)

Any thoughts? The "Date Range" cell I am referencing has different values in it so I need to basically search right of a dash (-).

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I have this line of code that seems to work in some modules but not in others. Can someone please tell me (in plain English) what the "-1" means in this line of code?

sDates = Right(daterangeballpractice, Application.WorksheetFunction.Find(" ", daterangeballpractice) - 1)

Any thoughts? The "Date Range" cell I am referencing has different values in it so I need to basically search right of a dash (-).

Thanks!
Well it took several threads before I found one where I thought I could help. Thanks for the question.

In this code, the "-1" is just being subtracted from the result of the find function to calculate how many characters at the right of the string named "daterangeballpractice" to keep.

Example, date range ball practice is 50 characters long. The first blank space " " is at character 27, so "sDates" will equal the last (27-1)=26 characters from that string.
 
Upvote 0
But if it's a dash you are looking for, then change the characters " " to "-" in the code.
 
Upvote 0
Thanks Fracin. I figured it was relatively easy but I didn't know how to say it in plain English, lol.
 
Upvote 0

Forum statistics

Threads
1,215,519
Messages
6,125,298
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top