Formula or Code

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
261
Hi All,

Thanks in advance

We have the following sheet

Excel 2010 32 bit
A
B
C
D
E
F
1
2
3
S.No.​
Year​
Batch​
Sams​
4
1​
9319​
3000​
5
2​
3219​
3200​
6
3​
7819​
3000,3200,8000​
8000​
7
4​
2419​
4000​
8
5​
1219​
2000​
9
6​
9319​
3000​
Sams​
10
7​
6819​
8000​
11
8​
9419​
4000​
12
9​
2419​
4000​
13
10​
8319​
3000​
14
11​
3519​
5000​
15
12​
5619​
6000​
Sheet: Sheet1

and this is my result sheet

Excel 2010 32 bit
A
B
C
D
E
F
20
21
22
S.No.​
Year​
Batch​
Flag​
23
1​
9319​
3000​
24
2​
3219​
3200​
25
3​
7819​
3000,3200,8000​
8000​
26
4​
2419​
4000​
27
5​
1219​
2000​
28
6​
9319​
3000,2000,4000​
3000​
Sams​
29
7​
6819​
8000​
30
8​
9419​
4000​
4000​
Sams​
31
9​
2419​
3000,8000,4000​
4000​
Sams​
32
10​
8319​
3000,8000,4000​
3000​
Sams​
33
11​
3519​
5000​
34
12​
5619​
6000​
Sheet: Sheet1

We want we will set from where it will start i mean will define the row from where formula will start

We want a Formula/Code who can check that if "Sams" are in column F, then it will take the above three values and paste as text on Column D, but we don't want any duplicate entry if there is any duplicate entry then it will add one more number from above

we hope above the sheet clear the points

help pls with code/formula
 

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
261
Pls provide VBA/Formula/Code

in my post VBA was not so that we have posted it again
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,893
Office Version
2007
Platform
Windows
Your example is complex, I reviewed it and did not understand.
You could explain step by step how you get from the source table to the destination table.
 

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
261
Your example is complex, I reviewed it and did not understand.
You could explain step by step how you get from the source table to the destination table.
In my sheet when the formula find "Sams" in column F, in sheet F28 we have find "Sams" so the formula have added E28,27 and 26 value in D28

Again we have find "Sams" in column F, in sheet F30 we have find "Sams" so the formula have added E30,29 and 28 value in D30 (Sorry we forget to add other value in result sheet)

same process will follow till the "Sams" will find and we will not used same value from column E, for example D32
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,893
Office Version
2007
Platform
Windows
Hi, try this:

The data must be in the cells as shown below.
<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:25.66px;" /><col style="width:38.02px;" /><col style="width:33.27px;" /><col style="width:127.37px;" /><col style="width:76.04px;" /><col style="width:76.04px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td > </td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td > </td><td >S.No.</td><td >Year</td><td > </td><td >Batch</td><td >Sams</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td > </td><td style="text-align:right; ">1</td><td style="text-align:right; ">9319</td><td > </td><td style="text-align:right; ">3000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td > </td><td style="text-align:right; ">2</td><td style="text-align:right; ">3219</td><td > </td><td style="text-align:right; ">3200</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td > </td><td style="text-align:right; ">3</td><td style="text-align:right; ">7819</td><td style="text-align:right; ">3000,3200,8000</td><td style="text-align:right; ">8000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td > </td><td style="text-align:right; ">4</td><td style="text-align:right; ">2419</td><td > </td><td style="text-align:right; ">4000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td > </td><td style="text-align:right; ">5</td><td style="text-align:right; ">1219</td><td > </td><td style="text-align:right; ">2000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td > </td><td style="text-align:right; ">6</td><td style="text-align:right; ">9319</td><td style="text-align:right; ">3000,2000,4000</td><td style="text-align:right; ">3000</td><td >Sams</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td > </td><td style="text-align:right; ">7</td><td style="text-align:right; ">6819</td><td > </td><td style="text-align:right; ">8000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td > </td><td style="text-align:right; ">8</td><td style="text-align:right; ">9419</td><td style="text-align:right; ">4000,8000,3000</td><td style="text-align:right; ">4000</td><td >Sams</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >12</td><td > </td><td style="text-align:right; ">9</td><td style="text-align:right; ">2419</td><td style="text-align:right; ">4000,8000,3000</td><td style="text-align:right; ">4000</td><td >Sams</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >13</td><td > </td><td style="text-align:right; ">10</td><td style="text-align:right; ">8319</td><td style="text-align:right; ">3000,4000,8000</td><td style="text-align:right; ">3000</td><td >Sams</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >14</td><td > </td><td style="text-align:right; ">11</td><td style="text-align:right; ">3519</td><td > </td><td style="text-align:right; ">5000</td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >15</td><td > </td><td style="text-align:right; ">12</td><td style="text-align:right; ">5619</td><td > </td><td style="text-align:right; ">6000</td><td > </td></tr></table>

Code:
Sub find_flag()
  Dim j As Long, n As Long, c As Range, s As String
  For Each c In Range("E4", Range("E" & Rows.Count).End(xlUp))
    s = ""
    If c.Offset(, 1) = "Sams" Then
      n = 0
      For j = c.Row To 4 Step -1
        If InStr(1, s, Cells(j, "E")) = 0 Then
          n = n + 1
          If n > 3 Then Exit For
          s = s & Cells(j, "E") & ","
        End If
      Next
    End If
    If s <> "" Then c.Offset(, -1) = "'" & Left(s, Len(s) - 1)
  Next
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,893
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,082,316
Messages
5,364,491
Members
400,802
Latest member
RichBRich

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top