I have a column that contains data for eg: 6B31-21045M22-AA
I'm trying to split the data before and after '-'. Like
A B C D
6B31-21045M22-AA 6B31 21045M22 AA
I tried
=LEFT(A2, SEARCH(“-”,A2)-1) and =Right(A2, SEARCH(“-”,A2)-1)
but if "-" occurs more than once then how do i split the 6B31-21045M22-AA or
6B31-21045M22-AA-SWQ
You don't need a formula or a VBA script. You can use Text to Columns function. Simply select the column with your data and use Text to Columns button on the Data panel. Then in a Wizard select Delimiter and set a "-" symbol as a delimiter.
With data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"-",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across:
(this can also be done with VBA)
EDIT#1:
Using VBA, select the cell you wish to process and run this:
Sub Splitter()
Dim ary, i As Long, a
With ActiveCell
ary = Split(.Value, "-")
i = 1
For Each a In ary
.Offset(0, i).Value = a
i = i + 1
Next a
End With
End Sub
Related
how to separate mixed email ids from cell range like
in column A all email ids are mixed with hyperlink i want to separate them each every single cell
Column A
krish#gmail.com hanu#gmail.com pradeep#gmail.com anish#gmail.com
i want to separate the mixed email ids to separate cell with hyperlink like this below mention
Column A
krish#gmail.com
hanu#gmail.com
pradeep#gmail.com
anish#gmail.com
Here's a general purpose formula for extracting the email addresses contained in column A into separate cells (eg B1,C1 etc).
Copied down/across as required.
=TRIM(MID(SUBSTITUTE(" "&$A1&" "," ",REPT(" ",40)),FIND(REPT("#",COLUMNS($A1:A1)),SUBSTITUTE(SUBSTITUTE(" "&$A1&" "," ",REPT(" ",40)),"#",REPT("#",COLUMNS($A1:A1)),COLUMNS($A1:A1)))-40,80))
If you are using Excel 365, in B1 insert:
=parsee(TEXTJOIN(" ",TRUE,A:A)," ")
where parsee() is this UDF:
Option Explicit
Public Function parsee(inpt As String, sep As String)
'
' spill-down version
'
Dim L As Long, i As Long, temp, arr
Dim lb As Long, ub As Long
If inpt = "" Then
parsee = ""
Exit Function
End If
If sep = "" Then
L = Len(inpt)
ReDim arr(1 To L, 1 To 1)
For i = 1 To L
arr(i, 1) = Mid(inpt, i, 1)
Next i
Else
temp = Split(inpt, sep)
lb = LBound(temp)
ub = UBound(temp)
ReDim arr(lb To ub, 1 To 1)
For i = lb To ub
arr(i, 1) = temp(i)
Next i
End If
parsee = arr
End Function
VBA is probably the quickest, but here's an alternative method w/out VBA. First, highlight your column A and go to Data...Text to Columns... Delimited... By Space. That will input each email address into their own cell.
Then insert an extra column to the left. So, column A is just a blank column.
Then create a pivot table (not in the usual fashion), by pressing ALT-D then P. Select "Multiple Consolidation Ranges" in the wizard's first window. Press Next.
Then select "Create a single page field for me" in the wizard, and press Next.
Then select your range (including the blank column). In this case, our range is A1:E4. Add that range, press Next.
Place the pivot into a new worksheet (or existing, your choice) and press FINISH.
Design your pivot by placing the "Value" field in the row area. Then filter to remove "blank" and change the design to remove Grand Total.
Now you have all emails stacked atop each other. If you want to create another column to retain their link, then you could add this as column B formula:
=HYPERLINK(A4,A4)
ORIGINAL DATA:
HOW IT LOOKS AFTER DELIMITING AND ADDING A BLANK COLUMN:
FINAL OUTPUT OF PIVOT AND OPTIONAL COLUMN B AS HYPERLINK:
You can use FILTERXML formula to split emails. In Office 365, a typical formula would be :
=FILTERXML("<t><d>"&SUBSTITUTE(A1," ","</d><d>")&"</d></t>","//d")
where A1 holds the input string you have posted.
In the attached table I would like to link cell contents via VBA.
Column A contains contents that should be linked to the cells in column B until a new content is added to A.
The example in the attached table is shortened. The tables are much longer.
I have made a 'before' and an 'after' sheet.
The code I have is linked from A to B until a new value comes into A. But the VBA always takes the newest value in column B and not all the previous ones.
How can I adjust the code so that all values from B are linked to A until a new value comes into column A?
Sub Linking_columns_until_new_values()
Dim arr
Dim z As Long
Dim txt As String
Dim ws As Worksheet
For Each ws In Worksheets
ws.Select
With ActiveSheet.UsedRange.Columns(1).Resize(, 2)
.Columns(1).SpecialCells(xlCellTypeBlanks).Font.Bold = False
arr = .Value
For z = 1 To UBound(arr)
If arr(z, 1) <> "" Then
txt = arr(z, 1)
ElseIf arr(z, 2) = "" Then
arr(z, 1) = ""
Else
arr(z, 1) = txt & " " & arr(z, 2)
End If
Next
.Value = arr
End With
Next
End Sub
Here is the link to the sheet:
https://www.evernote.com/l/AGApoCGk-OJGKaHxwB2F-VCjO9uWJN299TM/
There is no need to use VBA for this:
In B1, because it's first entry, I copied manually.
My formula in B2 is =IF(B2="";"";C1&B2) and drag down
My formula in C1 is =B1 and drag down
Later on you could copy/paste formats, paste values, and then delete columns A and B. That way you would get what you got in After Sheet
Probably you can use the macro recorder to get the code and adapt it to your needs if you need VBA solution.
Hope this helps
Lets say we have 5000 rows with random values (blanks, numbers, characters). I need to show type of all the cells in these 5000 rows in a single cell using a formula. Is it actually possible? I've tried to CONCATENATE(CELL("type";array)) and ctrl+shift+enter but it didn't work (it returns the type of the first cell in the array).
If you want to know, this is for finding a cell with text rather than values or blanks in a very big file. Maybe you have a better solution.
Thanks in advance.
UPD: thanks for macros but I can't use them in this workbook, I need a formula-solution.
UPD: I've got how to do it with conditional formatting => new rule => use a formula to determine... => use ISTEXT('first cell of the range') formula
But still, is it possible to create the formula?
The best way to go about this is to use MACROs
Here is my sample code:
Sub Button2_Click()
numRows = 10 ' Number fo rows to loop through, in your case 5000
'loop through each cell located in column 1
'Check its type
'Concatenate each one in 1 cell on the 8th column
For i = 1 To numRows
Sheet1.Cells(1, 8).Value = Sheet1.Cells(1, 8).Value & TypeName(Sheet1.Cells(i, 1).Value) & ","
Next i
End Sub
You can adapt this small user defined function to your needs.
Say we are looking at cells in the first row, from A1 through D1 and we want to concatenate their types into a single cell. Enter the following UDF() in a standard module:
Public Function KonKaType(rIN As Range) As String
Dim r As Range
For Each r In rIN
s = "cell(""type""," & r.Address(0, 0) & ")"
KonKaType = KonKaType & Evaluate(s)
Next r
End Function
and then in the worksheet cell E1 enter:
=KonKaType(A1:D1)
I have an Excel worksheet and am trying to figure out the formula for the following:
With my formula, I want to search all 700 rows of Column A for cells that contain aa_product11.12
Column A's value may or may not contain those values (some will, some will not). And, this is only the partial value. All of the cells have more data, i.e.
Column A
Sept01_aa_product11.12;
Oct01_aa_product11.12;
and so forth.
I need the full values of those cells that match, to show up in B1. So, the formula in B1 will search all of column A for aa_product11.12 and then B1 will look like:
Cell B1
Sept01_aa_product11.12, Oct01_aa_product11.12, Jan02_aa_product11.12,
Aug08_aa_product11.12
Thank you in advance for your help!
My answer will not immediately give you the concatenated results, but they are the step(s) before this:
Without formula:
Insert a filter and filter on Text with the criteria 'Contains aa_product11.12'.
Copy the column after the filter and paste the results in a fresh sheet.
You can then remove the filter and transfer the results back to the original sheet.
With a formula:
In B1, put the formula:
=IFERROR(INDEX($A$1:$A$700,SMALL(IF(ISNUMBER(FIND("aa_product11.12",$A$1:$A$700)),ROW($A$1:$A$700),9.9E+208),ROW())),"")
But this is an array formula which will require using Ctrl+Shift+ to work properly. After this, fill down the formula until there are no more results returned to proceed to the last step.
After doing either of these, you can run a CONCATENATE on the cells:
=CONCATENATE(B1,", ",B2,", ", ... )
Okay, You need to open your Visual Basic Editor and create a module. Place the following code in your module:
Function Get_Data()
Dim Strg As String
Dim Boo As Boolean
Boo = False
Dim i
i = 1
For i = i To 65000
Strg = Cells(i, 1).Value
If InStr(1, Strg, "aa_product11.12") Then
If Boo = True Then
Get_Data = Get_Data & Cells(i, 1).Value & ", "
Else
Get_Data = Cells(i, 1).Value & ", "
Boo = True
End If
End If
Next i
End Function
Save file as a Macro-Enabled workbook. Then go to cell B1 and type in: =Get_Data()
Press enter and the function should work. Let me know if you have any questions.
Let's supose 'large' excel like this:
A |B
ab |ef
|oo
ut |
|oo
ut |ef
That I need is a new row with a summary of all differents values of each column:
A |B
ab |ef
|oo
ut |
|oo
ut |ef
ab,ut |ef,oo <- new row with the 'summary'
Note: I can copy by hand the formula at end of each column, I only need the formula
Following is a function that can be used to Concatenate unique columns values in a cell
Function UniqueItem(InputRange As Range) As Variant
Dim cl As Range, cUnique As New Collection, cValue As Variant
Application.Volatile
On Error Resume Next
For Each cl In InputRange
If cl.Formula <> "" Then
cUnique.Add cl.Value, CStr(cl.Value)
End If
Next cl
UniqueItem = ""
For i = 1 To cUnique.Count
If UniqueItem = "" Then
UniqueItem = UniqueItem & cUnique(i)
ElseIf UniqueItem <> "" Then
UniqueItem = UniqueItem & ", " & cUnique(i)
End If
Next
On Error GoTo 0
End Function
How to use this function
1. Open excel file
2. Press Alt + F11
3. Create a new module and paste the code in it
4. Go back to the excel file and select the cell you want to have the result
5. Enter formula as =UniqueItem(A1:A5) A1:A5 specifies the range. You can specify any range.
Please find the sample file at the following link: Concatenate_different_columns_values_in_a_cell.xlsm
With some tricks (and an extra column) you can do this the following way.
In column A row 1 through 6, I placed some random text.
In column B I placed the following formulae.
B1: =IF(COUNTIF($A$1:$A1,A1)=1,A1&", ","")
B2: =IF(COUNTIF($A$1:$A2,A2)=1,A2&", ","")
B3: =IF(COUNTIF($A$1:$A3,A3)=1,A3&", ","")
B4: =IF(COUNTIF($A$1:$A4,A4)=1,A4&", ","")
B5: =IF(COUNTIF($A$1:$A5,A5)=1,A5&", ","")
B6: =IF(COUNTIF($A$1:$A6,A6)=1,A6&", ","")
B7: =SUBSTITUTE(B1&B2&B3&B4&B5&B6&",",", ,","")
The idea here is that the search list grows from row 1 to the end and marks any unique value. If the statement in B1 through B6 is true, the value from A is used and a , {space} is added.
In B7 I just concatenate all values, then I add an extra comma at the end.
The substitute removes the last ,{space}, with nothing, effectively making sure the list does not end with a comma.
You can paste the formula for B1 in cell B1 and then just paste the formula down. The relative reference automatically increases the search array.
Understand. One (not so elegant) way is the following... Set C1: = B1, the C2: =B1&B2, then copy C2 all the way down to the end.... On the other hand, I think this might be better served by a VBA solution.
Alternatively, you could use this...
http://mcgimpsey.com/excel/udfs/multicat.html
Regards,
Robert Ilbrink