How to concatenate based on number of duplicates - MS Excel - excel

Is there a way to concatenate multiple columns if the a row is duplicate? I have a spreadsheet where column A has duplicate team but there area and LD (column b and c) are different value. I would like to have a formulate at column E where it will concatenate column B and C with dash and append next row values. See the attached picture highlighted row E. Any idea how to do this with excel formula or may be VBA. I tried this formula in column E =IF(A3=A4,D3&";"&D4) but it returns false for the last duplicate row.

This is not possible with formulas. It requires a VBA-based solution.
I wrote a custom routine for you. Please place this in a standard code module:
Public Sub ConcatTeamZones()
Const SOURCE = "A1"
Const OUTPUT = "E1"
Dim i&, j&, s$, v, w
v = Range(SOURCE).CurrentRegion
ReDim w(1 To UBound(v), 0)
For i = 2 To UBound(w)
If v(i, 1) <> v(i - 1, 1) Then
w(i - 1, 0) = s
s = s & v(i, 2) & "-" & v(i, 3)
s = ""
Else
s = s & ";"
End If
s = s & v(i, 2) & "-" & v(i, 3)
Next
w(i - 1, 0) = s
Range(OUTPUT).Resize(UBound(w)) = w
End Sub
And then from the worksheet with your team data, press ALT-F8 to bring up the Macro Dialog. Run the ConcatTeamZones macro.
Note 1: this assumes that column A is sorted.
Note 2: You can edit the first two lines to specify which columns contains the source (team data) and which column you wish the output.

It can be done using formulas, it’s just a matter of perspective:
Assuming data is sorted by Team
This formula gives the concatenated result with the maximum of combinations on top. Enter this formula in cell E2 and copy till last record.
=CONCATENATE($D2,IF(EXACT($A2,$A3),";"&$E3,""))
To assign the max possible combinations to each Team enter this formula in F2 and copy till last record.
=INDEX($E:$E,MATCH($A2,$A:$A,0),0)

Here's how I would do it...
Cell "A1": =COUNTIF(B$2:B2,B2)&B2 - This is to create a unique key. Copy down the length of your table
Then I would use an advanced query (with vba maybe) to create a list of unique values for team in the "F" column
Cell "G2": =VLOOKUP("1"&F2,A:D,3,0)&"-"&VLOOKUP("1"&F2,A:D,4,0)&IF(ISERROR(VLOOKUP("2"&F2,A:D,3,0)),"",", "&VLOOKUP("2"&F2,A:D,3,0)&"-"&VLOOKUP("2"&F2,A:D,4,0))&IF(ISERROR(VLOOKUP("3"&F2,A:D,3,0)),"",", "&VLOOKUP("3"&F2,A:D,3,0)&"-"&VLOOKUP("3"&F2,A:D,4,0))&IF(ISERROR(VLOOKUP("4"&F2,A:D,3,0)),"",", "&VLOOKUP("4"&F2,A:D,3,0)&"-"&VLOOKUP("4"&F2,A:D,4,0))
This function creates your combined references. It would be longer if you expected more than 4 occurrences of teams.
Just copy "IF(ISERROR(VLOOKUP("4"&F2,A:D,3,0)),"",", "&VLOOKUP("4"&F2,A:D,3,0)&"-"&VLOOKUP("4"&F2,A:D,4,0))" and change the "4" to "5" etc
You could hide column A (to tidy up).
Sorry, I tried to include an image but insufficient reputation :-)

Related

how to separate mixed email ids from cell

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.

How to copy the number if contains certain number (first 4 digit) to another column - EXCEL VBA

I'm trying to search on the specific column(E), and if matched with the first 4 digit, I would like to copy the number to a different column.
Column E is where i would like to paste all the random number(dynamic)
Column A/B/C is static where i would add 4 digits from time to time.
Column I/J/K is where is would like to paste the result.
PS:
I'm doing it manually and would really appreciate if someone can help me out with the automation hence no code is provided. :(
Having ExcelO365 means you may use FILTER(). Therefor try the below:
Formula in I2:
=FILTER($E:$E,ISNUMBER(MATCH(--LEFT($E:$E,4),A:A,0)))
Drag right to K2. Now, this is dynamic and will change accordingly upon data entry in column E:E, or changing values in A:C.
this is the code to execute on sheet 1, it goes through the entire column E and validates through the formula of counting if in each of the first three columns and assigns the value found in the corresponding columns.
Sub macro()
Dim Static_Data As String
Dim Sht As Worksheet
Set Sht = ThisWorkbook.Sheets("Hoja1")
Active_row = 2
Do While Sht.Range("E" & Active_row).Value <> ""
Static_Data = Sht.Range("E" & Active_row).Value
For i = 1 To 3
If Application.WorksheetFunction.CountIf(Sht.Columns(i), Mid(Static_Data, 1, 4)) > 0 Then
Sht.Cells(Sht.Cells(Rows.Count, i + 8).End(xlUp).Row + 1, i + 8).Value = Static_Data
End If
Next i
Active_row = Active_row + 1
Loop
End Sub
For Excel versions that don't support FILTER or as an alternative you can use standard formulas for this.
If you use columns F-H as helper columns (and these columns can be hidden) then the formula in F2 will be:
=IF(NOT(ISERROR(VLOOKUP(VALUE(LEFT($E2,4)),A$2:A$100,1,FALSE)))=TRUE,$E2,"")
The formula can then be copied across and down. This will find your matches.
In order to then remove the blanks from the data you can use the following formula in I2 and again copy across and down. Depending on how many numbers you want to add in, you may want to extend the range A$2:A$100 in the top formula and F$2:F$100 in the bottom formula
=IFERROR(INDEX(F$2:F$100,AGGREGATE(15,6,(ROW(F$2:F$100)-ROW(F$2)+1)/(F$2:F$100<>""),ROWS(I$2:I2))),"")

Combine Adjacent Row Cells Depending on their Left Column Cell

I'd like to combine cells in the right column into one cell according to the adjacent cell on the left. I tried Merging but I could only get so far. And after searching online I couldn't find anything that can parse each row and combine for the length of the left cell's span. I know it's a CONCATENATE function, but how would I get it to parse the whole spreadsheet?
This is an example of the results I would want for the above:
This may be too complicated - in which case I would go back to the drawing board and do a full VBA version, but initially I was looking for a challenge to construct a solution only using formulas. Unfortunately, there appears to be no standard formula-based approach to concatenate a variable number of cells.
So, to accomplish this, I added one function:
Function CombineRange(ByRef rng As Range, ByVal delim As String)
Dim arr
Dim i As Long
arr = rng.Value
CombineRange = ""
For i = 1 To UBound(arr)
If i > 1 Then
CombineRange = CombineRange & delim
End If
CombineRange = CombineRange & arr(i, 1)
Next i
End Function
Assumptions:
your data is in a sheet called "YourData"
Your merged data is column A
Your "single row" data is column B
Row 1 is some kind of header row.
Next, set up four columns on a new sheet (I call it "Collapsed")
A - Start Row = (first row) whatever row your data starts on (2, in our case)
A - Start Row = (all others) A2+B2
B - Offset = {IFERROR(MATCH(FALSE,ISBLANK(INDIRECT(ADDRESS(A2+1,1,,,"YourData")&":A200")),0),0)}
Note this is an array function, so you need to do shift+Enter when entering it
C - Level1 = =INDEX(YourData!A:A,A2)
D - Combined Level 2 = =IF(B2<=1, INDIRECT(ADDRESS(A2,2,,,"YourData")), CombineRange(INDIRECT(ADDRESS(A2,2,,,"YourData")&":"&ADDRESS(A2+B2-1,2)),"; "))

excel vba remove duplicates

I have the below table :
Name, Total, Email Address Date
Test1,12,test1#hotmail.com 12/12/2012
Test2,12,test1#hotmail.com 12/05/2015
Test2,12,test1#hotmail.com 12/05/2015
Test3,12,test1#hotmail.com 12/07/2016
I want to match on Name, Email Address and Date. If an existing record is found then I want to merge them and add the totals together. e.g.
Test2,12,test1#hotmail.com 12/05/2015
Test2,12,test1#hotmail.com 12/05/2015
would become
Test2,24,test1#hotmail.com 12/05/2015
What options do I have?. If i iterate sequentially and check for every one it would take a substantial amount of time.. (was thinking to use range check and check current row against all, if found then delete and add a new row).Would appreciate some examples.
You can add a 5th column and CONCAT columns Name,Email,Date, with commas between them. E.g. Test1,test1#hotmail.com,12/12/2012.
Export this column in another sheet and apply Remove duplicates so you have unique data.
Now apply a SUMIF according to this column and sum data from Total as:
SUMIF(range:"your tabel",criteria: the 5th column, sum range: column Total)
Assuming:
The list is sorted by ColA
Your table header is in Row3
There is only 1 duplicate
If ColA is the same, so are C and D
Dim i As Integer
Dim cellCount As Integer
cellCount = Application.CountA(Range("A:A")) - 1
For i = 4 To cellCount
If (Cells(i, "A").Value = Cells(i + 1, "A").Value) Then
Cells(i, "B").Value = Cells(i, "B").Value + Cells(i + 1, "B").Value
End If
Next i
ActiveSheet.Range("A:D").RemoveDuplicates Columns:=1, Header:=xlYes
why not simply have column E sum the values like this:
=SUMIFS(B:B,A:A,"="&A2,C:C,"="&C2,D:D,"="&D2)
and when you finish copy as values and remove duplicates using the function on the ribbon? this way you can copy at the end column E to column B and be done with it in a couple of minutes
edited: clarity and steps
those are the steps needed
place the following formula in cell E1, and pull it down until it's in all of column E until the end of the data
=SUMIFS(B:B,A:A,"="&A2,C:C,"="&C2,D:D,"="&D2)
copy column E into column E - as values
use excel's remove duplicates function
copy column E to column B
and that's the full steps needed to accomplish your task.

How to combine 2 seperate arrays to an extensive combined list in excel

I've been looking for it everywhere but I can't seem to find the answer although it seems an regular problem.
I'm trying to automate the duplication of cells in excel.
I have two lists: list 1 with values 1,2,3,4 and the second list is with values a,b,c,d.
Now I want to have a file where for every value in list 1, the values in list two are duplicated in excel. So:
1 - a
1 - b
1 - c
1 - d
2 - a
2 - b
2 - c
2 - d
3 - a
...
I'm wondering if there's a function within excel or if not a macro that I could use to solve this? For this short list it is of course easy to do with autofill, but when the list consists of a few hundred values, it gets more complicated...
You can do this also with a few formulas/support columns without VBA:
Let's assume your first category is in column A, starting in A2 and your category is in column B.
Determine the record count for each category, e.g. in C1: =COUNTA($A:$A)-1 (assuming a header row) and C2 equivalent
Place two support column, e.g. in E and F) - E will hold the row for the first category and F the Id for the second category. Place the following formula in E2: =IF(ISTEXT(E1),1,IF(F2=1,E1+1,E1)) and this in F2: =IF(ISTEXT(F1),1,IF(F1=$C$2,1,F1+1))
Add two more columns for the final result - G for category one with formula =INDEX(A:A,E2+1) and H for category 2 with the formula =INDEX(B:B,F2+1).
Now simply copy the formulas for the columns E:H down for a many rows as required (number of rows required is =C1*C2
In the end it'll look something like this:
You can download the file here.
This should be really easy to understand ...
Open VBE ALT+F11 and right click VBA project. Insert a Module and copy-paste the below code. Hit F5 to run
Sub Main()
Dim number As Range
Dim letter As Range
For Each number In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
For Each letter In Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
With Sheet2
.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row + 1) = number
.Range("B" & .Range("b" & Rows.Count).End(xlUp).Row + 1) = letter
End With
Next
Next
End Sub
The above code assumes that your sheet1 looks like this
and the results will be on Sheet2 like this

Resources