Separate a comma delimited string located in a cell to a column - excel

I have a comma delimited string (aad,adaa,,dadae,,,eresa,,baaa) in cell A1 of Sheet1 which I want to split and insert values in a column such as:
aad
adaa
dadae
eresa
baaa
Empty values will skip a cell and insert the string in next cell.
I am able to separate the string to a row but how could I do it to a column?
Here is my line to split the string to a row:
Sheets("Sheet1").Range("A1").TextToColumns

Call WorksheetFunction.Transpose() after splitting to columns.
No need to use TextToColumns either, Split will suffice:
Range("A1:A9").value = WorksheetFunction.Transpose(Split("aad,adaa,,dadae,,,eresa,,baaa", ","))

Related

Excel, covert row cell into comma separated list

I have a excel sheet having n number of rows with six columns
I need to insert all these rows into a database table.
So I want to convert each row cells into comma separated and marked by quote list.
Also if any cell is empty then its value should be marked as empty string('')
Example:
Sample image
Try this.
=IF(A1>0,"'"&A1&"', ",""",")&IF(B1>0,"'"&B1&"', ",""",")&IF(C1>0,"'"&C1&"', ",""",")&IF(D1>0,"'"&D1&"', ",""",")&IF(E1>0,"'"&E1&"', ",""",")&IF(F1>0,"'"&F1&"'", """,")
Use TEXTJOIN with "do not skip empty cells" and use quote-comma-quote as the join. Prepend and append a single quote, and you're done:
="'" & TEXTJOIN("','",FALSE,A1:F1) & "'"

Excel formula : Grab the column name corresponding to particular cell

In Above excel sheet i need a formula which will extract that particular column name where "1" is present and enter that name in the corresponding cell. Example- In above Image each row corresponding to col "Tags" contain the column name whose corresponding cell contain "1".
For a 4 column example you can use this:
=SUBSTITUTE(TRIM(IF(A2,$A$1,"")&" "&IF(B2,$B$1,"")&" "&IF(C2,$C$1,"")&" "&IF(D2,$D$1,""))," ",", ")
For 7 columns, just add additional IF statements inside the TRIM following the same pattern.
The formula relies on 1=TRUE to keep it short. The result each IF is followed by a space. The TRIM gets rid of extra spaces left when no 1 occurs. Finally SUBSTITUTE converts into , so you get a comma delimited list.
Note that:
TRIM strips extra spaces from text, leaving only single spaces between words and no space characters at the start or end of the text.
couldn't find a non vba solution for concatenating a range. So here is a UDF
Function conCatRange(ByVal criteriaRange As range, _
ByVal criteria As String, _
ByVal conRange As range, _
ByVal separator As String) As String
Dim c As range
conCatRange = ""
For i = 1 To conRange.Columns.Count
If (criteriaRange(1, i) = criteria) Then
conCatRange = conCatRange & conRange(1, i) & separator
End If
Next i
conCatRange = Left(conCatRange, Len(conCatRange) - 1)
End Function
criteriaRange = Range you want check for 1s,
criteria = 1 (in your case)
conRange = header range
separator = ","
if you want to add summary and parameter descriptions see this link
How to put a tooltip on a user-defined function
Supposing your header range is A-K,
You could you use this formula from L2 onwards:
=IF(MID(TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")),1,2)=", ",MID(TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&$C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")),3,1000),TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")))
This formula has a limit of 1000 character in column by the mid function. and it repeats 3 times the same formula because of the separator: ", " but if you dont mind the result format you can short it to one. just fill put 1 in columns and the column name will appear.
Hope this helps.

Excel: extract only substrings beginning with a certain character

I have a column of cells containing a variable amount of text up to 140 characters in length. What I would like to do is write a function that will parse these strings for only words beginning with "#" and organize them in a single adjacent cell separated by spaces.
These substrings vary in length and in their position within the string. And there might be more than one substring beginning with "#" in the cell to pull.
I have tried it in many different ways which have been unsuccessful. Thanks in advance for your advice!
Here is a way that seems to work, but is probably not the "correct" way:
The objective was to parse column C, containing tweets, for all the "mentions" (strings beginning with #) and put them in an adjacent cell in column D.
I took all the content from column C and pasted it into a new sheet. Then I did text-to-column so that the tweet was put into cells word by word. On these cells I used the function (dragged out) =IF(ISNUMBER(FIND("#",B3)),CONCATENATE(B3," "),"") in order to separate the twitter handles only into columns below. I think there needs to be a space added in case there are multiple handles to join.
Then I used another nested CONCATENATE function =CONCATENATE(IF(B34="","",B34),IF(B35="","",B35)...,IF(B65="","",B65) to put the handles, now followed by spaces, together in a single cell. It had to be written this way as a workaround for the #VALUE error for the CONCATENATE function in blank cells.
Then I selected the whole row, copied and transposed it into a column. Then selected the column, pasted values only into my original sheet in column D. The handles all line up with the corresponding tweet.
I would love to learn how to do this in the proper way.
Dim regEx As Object
Dim strPattern As String: strPattern = "^#"
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = strPattern
If regEx.Test(valueOfCellToCheck) Then
' do your logic here
Else
' skip cell
End If

Using concatenate and decode in excel

I have a column having values as
A
1.decode(D01,1,1,3,3,4)
2.decode (d02,1,1,3,3,4)
3.decode(d03,1,1,3,3,4)
...
...
31.decode(d31,1,1,3,3,4)
and i need to have these columns in a string seperated by comma as
decode(D01,1,1,3,3,4), decode (d02,1,1,3,3,4), decode(d03,1,1,3,3,4)
and so forth up to 31 such values in a comma separated list.
How will I be able to do this in excel?
You can do a CONCATENATE over all the rows like:
=CONCATENATE(A1&", "&A2&", "&A3&", "&A4&", "&A5&", "&A6&", "&A7&", "&A8&", "&A9&", "&A10&", "&A11&", "&A12&", "&A13&", "&A14&", "&A15&", "&A16&", "&A17&", "&A18&", "&A19&", "&A20&", "&A21&", "&A22&", "&A23&", "&A24&", "&A25&", "&A26&", "&A27&", "&A28&", "&A29&", "&A30&", "&A31)
Or You can create and use something like the ConcatenateRange presented in this answer
Or You can do:
Set cell B1 to "=A1"
Set cell B2 to "=B1&", "&A2"
Copy cell B2 all the way down to B31
Cell B31 will now contain the concatenated text string you are looking for.

Writing strings into excel using Matlab?

I am writing a cell array of string into Excel from Matlab. I have a cell array data{} that I am trying to write into Matlab. It should writting three large lengths of strings to excel since the strcmp passes 3 times. Currently it is only writing the last set of strings into excel. data = { {1x25} {1x35} {1x20} } looks like this. Also I would like to be able to write the data into three cells instead of getting copyied into as many cells as there are lines in the element of the cell array. Is this possible to do with Matlab to excel?
done = {}
for i = 1:3
q = strcmp(x_gene_ID{i},locus_tags{i});
if q ==1
done{end+1} = data{i};
disp(done);
end
end
w = xlswrite('data.xlsx',done','E2:E400');
Ok that helps I am aware the cell array's are larger than 3 cell range. I am trying to get the Nx1 cell array to fit into one cell in Excel because It needs to correspond to information in an adjacent cell. Is this at all possible to do?
A B C D E
w Rv0146 na Rv0039c (i want the cell array1 to go here)
s Rv0156 na Rv0029c (i want the cell array2 to go here)
s Rv0156 na Rv0029c (i want the cell array2 to go here)
Here is what I am looking to do in excel
UPDATED ANSWER:
If I understand correctly, it appears that your variable data is a cell array where each cell contains a 1-by-N (or perhaps N-by-1) cell array of strings. If you want to try and fit each of these cell arrays of strings into one cell of a spreadsheet, you are going to need to format each into a single long string first.
Here's an example of how you could format the cell arrays of strings by concatenating them together with a newline between them:
data = {{'hello' 'hi' 'hey'} ... %# Sample cell array of 1-by-N
{'world' 'earth' 'everyone'} ... %# cell arrays of strings
{'blah' 'blah'}};
data = cellfun(#(x) {strcat(x,{char(10)})},data); %# Add newline characters
%# to the string ends
data = cellfun(#(x) {deblank([x{:}])},data); %# Concatenate the inner cells and
%# remove the trailing newlines
Now that each cell array of strings is just a single long string, each string can be written to a cell of an Excel spreadsheet as follows:
xlswrite('data.xls',data(:),'Sheet1','E2'); %# Write the data to cells E2 to E4
And here's what the resulting spreadsheet looks like:
If you use a space ' ' instead of a newline character, here's what the spreadsheet looks like (after adjusting the row and column widths):
Functions used in the above code: CELLFUN, STRCAT, CHAR, DEBLANK, XLSWRITE.

Resources