ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   string output needed (https://www.excelbanter.com/excel-programming/322003-string-output-needed.html)

David

string output needed
 
Hi,
Using XL2K, I have a Worksheet_Change event that accepts user input for 1
or 2 check amts. The user is then prompted for store name(s), Payee1 and
*maybe* Payee2 via either 1 or 2 userforms. I need Payee1 and *maybe*
Payee2 placed as a single line to the right of the check amt(s).
Currently I use the following:

Target.Offset(0, 1) = Payee1 + " " + Payee2

This way if there is only 1 payee, Payee2 won't appear. That's what I want,
except instead of using spaces, I want Payee1 and Payee2 (if there is one)
separated by a '/'. If there is only 1 payee, I don't want the '/' to
appear.

What code will accomplish what I want?

--
David

Rob van Gelder[_4_]

string output needed
 
You didn't say how you know Payee2 is valid or not. Assuming that Payee2 =
"" when invalid.
Target.Offset(0, 1).Value = Payee1 & iif(Payee2="", "", "/" + Payee2)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"David" wrote in message
...
Hi,
Using XL2K, I have a Worksheet_Change event that accepts user input for 1
or 2 check amts. The user is then prompted for store name(s), Payee1 and
*maybe* Payee2 via either 1 or 2 userforms. I need Payee1 and *maybe*
Payee2 placed as a single line to the right of the check amt(s).
Currently I use the following:

Target.Offset(0, 1) = Payee1 + " " + Payee2

This way if there is only 1 payee, Payee2 won't appear. That's what I
want,
except instead of using spaces, I want Payee1 and Payee2 (if there is one)
separated by a '/'. If there is only 1 payee, I don't want the '/' to
appear.

What code will accomplish what I want?

--
David




David

string output needed
 
Rob van Gelder wrote

You didn't say how you know Payee2 is valid or not. Assuming that
Payee2 = "" when invalid.
Target.Offset(0, 1).Value = Payee1 & iif(Payee2="", "", "/" + Payee2)


Thanks. You assume correctly. If there is only one payee, the user is never
even prompted for Payee2 in which case Payee2="". After posting, I was able
to stumble/fumble my way to a solution eerily similar to yours:

Target.Offset(0, 1) = iif(Payee2 = "", Payee1, Payee1 + "/" + Payee2)

This after successfully implementing an less elegant If/Then/Else solution,
but I was after a one-liner.

--
David


All times are GMT +1. The time now is 01:30 PM.

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