I frequently need to convert a range of Excel data into an ANY() function format (table below) for PeopleSoft queries. Once I convert the format, I copy/paste into PeopleSoft. First column is an example of original data and the second column is the end result. Maybe I can just use custom formatting, but I haven't found the right format setting. I'm thinking of two approaches depending on the circumstance:
Sample Data. The last row (closing parenthesis) could be tacked on to 'Oranges') or put below the data in a new cell
<tbody>
</tbody>
Thank you in advance for any suggestions!
- Option A: convert the values to the new format in their existing location. I've been fiddling around with something like:
Code:
Sub ANY_Function_OptionA()
Dim r As Range
Set r = Application.Selection
rangeValues = r.Value
r.Value = "'" & rangeValues & "',"
End Sub
- Option B is to use a formula and offset to the next empty column to the right. Problem is, the next empty column isn't always 3 columns to the right as in the code below. Any suggestions on how best to offset to the next empty column? Or any suggestions of how to improve this code - I threw it together in a hurry and I know it's a bit ugly.
Code:
Sub ANY_Function_OptionB()
Range(Selection, Selection.End(xlDown)).Select
For Each c In Selection
c.Offset(0, 3).FormulaR1C1 = "=CHAR(39)& c.value &CHAR(39)&CHAR(44)"
Next
End Sub
Sample Data. The last row (closing parenthesis) could be tacked on to 'Oranges') or put below the data in a new cell
Product | ANY( |
Apples | 'Apples', |
Bananas | 'Bananas', |
Oranges | 'Oranges' |
) |
<tbody>
</tbody>
Thank you in advance for any suggestions!