how to add "numbers and ad" with some condition in same cells

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
533
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
Hi,

Please check the following and update how can we do that

Sample data

Excel 2010 32 bit
A
B
C
D
E
1
Sample​
2
3
4
5
6
1​
7
2​
8
3​
9
4​
Yes​
10
5​
Yes​
11
6​
Yes​
Yes​
12
7​
Yes​
Yes​
13
8​
Yes​
Yes​
14
9​
Yes​
15
10​
Yes​
16
11​
17
12​
18
13​
19
14​
20
15​
21
Sheet: Sheet1

Result Data

Excel 2010 32 bit
A
B
C
D
E
1
Result in same cells B6:D20​
2
3
4
5
6
1​
7
2​
8
3​
9
4​
Yes 5​
10
5​
Yes 4​
11
6​
Yes 3​
Yes 5​
12
7​
Yes 2​
Yes 4​
13
8​
Yes 1​
Yes 3​
14
9​
Yes Ad​
Yes 2​
15
10​
Yes Ad​
Yes 1​
16
11​
Yes Ad​
Yes Ad​
17
12​
Yes Ad​
Yes Ad​
18
13​
Yes Ad​
Yes Ad​
19
14​
Yes Ad​
Yes Ad​
20
15​
Yes Ad​
Yes Ad​
21
Sheet: Sheet1


help pls
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What is the logic to put the result?
In columns C and D do you have formulas or values?
 
Upvote 0
in the above we have started the add in every column
First Yes - "add 5"
Second Yes - "add 4"
Third Yes - "add 3"
Fourth Yes - "add 2"
Fifth Yes - "add 1"
Sixth Yes - "ad"
Seventh Yes - "ad"
Eighth Yes - "ad"

we have more column, its a sample data
 
Upvote 0
The first "Yes" in the column should always start with 5?
Decrease until reach 1 and then everyone carries the word "Ad"
 
Upvote 0
If there are always 5 Yes in the column, then try the following:

Code:
Sub add_numbers_ad()
  Dim a() As Variant, b() As Variant, entre As Boolean
  Dim lr As Long, lc As Long, i As Long, j As Long, n As Long
  lr = Range("B" & Rows.Count).End(xlUp).Row
  lc = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
  a = Range("C7", Cells(lr, lc))
  ReDim b(1 To UBound(a, 1), 1 To lc - 2)
  For j = 1 To lc - 2
    entre = False
    n = 5
    For i = 1 To UBound(a, 1)
      If a(i, j) = "Yes" Then
        entre = True
        b(i, j) = "Yes " & n
        n = n - 1
      Else
        If entre Then b(i, j) = "Yes Ad"
      End If
    Next
  Next
  Range("C7").Resize(UBound(a, 1), lc - 2).Value = b()
End Sub
 
Upvote 0
we have check and there are some errors, pls check the following sheet after running the formula

Excel 2010 32 bit
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
1
2
3
4
5
6
7
8
1​
9
2​
10
3​
11
4​
Yes 5​
Yes 5​
Yes 5​
Yes 5​
Yes 5​
12
5​
Yes​
Yes 4​
Yes 4​
Yes 4​
Yes 4​
Yes 4​
13
6​
Yes​
Yes 3​
Yes 3​
Yes 5​
Yes 3​
Yes 5​
Yes 3​
Yes 5​
Yes 5​
Yes 5​
Yes 3​
14
7​
Yes​
Yes 2​
Yes 2​
Yes 4​
Yes 2​
Yes 4​
Yes 2​
Yes 5​
Yes 4​
Yes 4​
Yes 4​
Yes 5​
Yes 2​
Yes 5​
15
8​
Yes​
Yes 1​
Yes 1​
Yes 3​
Yes 1​
Yes 3​
Yes 1​
Yes 4​
Yes 3​
Yes 3​
Yes 3​
Yes 5​
Yes 5​
Yes 4​
Yes 1​
Yes 4​
16
9​
Yes​
Yes Ad​
Yes Ad​
Yes 2​
Yes Ad​
Yes 2​
Yes Ad​
Yes 3​
Yes 2​
Yes 2​
Yes 2​
Yes 4​
Yes 5​
Yes 4​
Yes 3​
Yes Ad​
Yes 3​
17
10​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
18
11​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
Yes​
19
12​
Yes​
Yes​
Yes​
Yes​
20
13​
Yes​
Yes​
21
14​
Yes​
Sheet: Sheet1
 
Upvote 0
Where are you going to put the numbering 1,2,3,4... in column B or column A?

In your first example you put it in column B. The macro works for column B.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

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