Formula or Code

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
530
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Pls provide VBA/Formula/Code

in my post VBA was not so that we have posted it again
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,560
Latest member
Torchwood72

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top