VBA Formula

Vishaal

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

Thanks in advance,

I have the following sheet

Excel 2010 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]
S.No.​
[/td][td]
25689​
[/td][td]
365478​
[/td][td]
2569​
[/td][td]
25698​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]
[/td][td]
2564​
[/td][td]
2145​
[/td][td]
1425​
[/td][td]
1478​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]
1​
[/td][td]
25​
[/td][td]
5​
[/td][td]
8​
[/td][td]
20​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]
2​
[/td][td]
30​
[/td][td]
10​
[/td][td]
10​
[/td][td]
23​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]
3​
[/td][td]
35​
[/td][td]
20​
[/td][td]
12​
[/td][td]
26​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td]
4​
[/td][td]
40​
[/td][td]
30​
[/td][td]
14​
[/td][td]
29​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td]
5​
[/td][td]
45​
[/td][td]
40​
[/td][td]
16​
[/td][td]
31​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td]
6​
[/td][td]
50​
[/td][td]
50​
[/td][td]
18​
[/td][td]
33​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td]
7​
[/td][td]
55​
[/td][td]
[/td][td]
19​
[/td][td]
36​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td]
8​
[/td][td]
60​
[/td][td]
[/td][td]
[/td][td]
39​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td]
9​
[/td][td]
65​
[/td][td]
[/td][td]
[/td][td]
41​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td]
10​
[/td][td]
70​
[/td][td]
[/td][td]
[/td][td]
42​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td]
11​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
43​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td]
12​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet1[/td][/tr][/table]

and need the following result in same sheet

Excel 2010 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]
S.No.​
[/td][td]
25689​
[/td][td]
365478​
[/td][td]
2569​
[/td][td]
25698​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]
[/td][td]
2564​
[/td][td]
2145​
[/td][td]
1425​
[/td][td]
1478​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]
1​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]
2​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]
3​
[/td][td]
[/td][td]
Yes​
[/td][td]
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td]
4​
[/td][td]
[/td][td]
Yes​
[/td][td]
Yes​
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td]
5​
[/td][td]
[/td][td]
Yes​
[/td][td]
Yes​
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td]
6​
[/td][td]
[/td][td]
Yes​
[/td][td]
Yes​
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td]
7​
[/td][td]
Yes​
[/td][td]
[/td][td]
Yes​
[/td][td]
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td]
8​
[/td][td]
Yes​
[/td][td]
[/td][td]
[/td][td]
Yes​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td]
9​
[/td][td]
Yes​
[/td][td]
[/td][td]
[/td][td]
Yes​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td]
10​
[/td][td]
Yes​
[/td][td]
[/td][td]
[/td][td]
Yes​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td]
11​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
Yes​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td]
12​
[/td][td]
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet1[/td][/tr][/table]

We have added the "Four Yes" from bottom in every column and removed the all numbers

Pls provide the solution
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Means nothing to me or indeed anyone else

Please provide more info regarding the logic applied
 
Upvote 0
Let me know if this is what you are looking for.


Book1
ABCDEFGHIJK
1S.No.25689365478256925698S.No.25689365478256925698
225642145142514782564214514251478
3
412558201
52301010232
63352012263Yes
74403014294YesYes
85454016315YesYes
96505018336YesYes
1075519367YesYes
11860398YesYes
12965419YesYes
1310704210YesYes
14114311Yes
151212
Sheet1


Code:
Sub STSIW()
Dim r As Range: Set r = Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant: AR = Application.Transpose(r.Value)


For col = 2 To UBound(AR)
    For Ro = 4 To UBound(AR, 2)
        If AR(col, Ro) = "" Then
            For j = Ro - 4 To Ro - 1
                AR(col, j) = "Yes"
            Next j
            Exit For
        Else
            AR(col, Ro) = ""
        End If
    Next Ro
Next col


Range("G1").Resize(UBound(AR, 2), UBound(AR)).Value = Application.Transpose(AR)


End Sub
 
Upvote 0
or ...

BEFORE

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][th]
G
[/th][th]
H
[/th][th]
I
[/th][th]
J
[/th][th]
K
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]S.No.[/td][td]
25689​
[/td][td]
365478​
[/td][td]
2569​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td][/td][td]
2564​
[/td][td]
2145​
[/td][td]
1425​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td=bgcolor:#FFFFFF]
1​
[/td][td=bgcolor:#FFFFFF]
25​
[/td][td=bgcolor:#FFFFFF]
5​
[/td][td=bgcolor:#FFFFFF]
8​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td=bgcolor:#FFFFFF]
2​
[/td][td=bgcolor:#FFFFFF]
30​
[/td][td=bgcolor:#FFFFFF]
10​
[/td][td=bgcolor:#FFFFFF]
10​
[/td][td=bgcolor:#FFFFFF]
23​
[/td][td=bgcolor:#FFFFFF]
23​
[/td][td=bgcolor:#FFFFFF]
23​
[/td][td=bgcolor:#FFFFFF]
23​
[/td][td=bgcolor:#FFFFFF]
23​
[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td=bgcolor:#FFFFFF]
3​
[/td][td=bgcolor:#FFFFFF]
35​
[/td][td=bgcolor:#FFFFFF]
20​
[/td][td=bgcolor:#FFFFFF]
12​
[/td][td=bgcolor:#FFFFFF]
26​
[/td][td=bgcolor:#FFFFFF]
26​
[/td][td=bgcolor:#FFFFFF]
26​
[/td][td=bgcolor:#FFFFFF]
26​
[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td=bgcolor:#FFFFFF]
4​
[/td][td=bgcolor:#FFFFFF]
40​
[/td][td=bgcolor:#FFFFFF]
30​
[/td][td=bgcolor:#FFFFFF]
14​
[/td][td=bgcolor:#FFFFFF]
29​
[/td][td][/td][td=bgcolor:#FFFFFF]
29​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td=bgcolor:#FFFFFF]
5​
[/td][td=bgcolor:#FFFFFF]
45​
[/td][td=bgcolor:#FFFFFF]
40​
[/td][td=bgcolor:#FFFFFF]
16​
[/td][td=bgcolor:#FFFFFF]
31​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td=bgcolor:#FFFFFF]
6​
[/td][td=bgcolor:#FFFFFF]
50​
[/td][td=bgcolor:#FFFFFF]
50​
[/td][td=bgcolor:#FFFFFF]
18​
[/td][td=bgcolor:#FFFFFF]
33​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td=bgcolor:#FFFFFF]
7​
[/td][td=bgcolor:#FFFFFF]
55​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
19​
[/td][td=bgcolor:#FFFFFF]
36​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td=bgcolor:#FFFFFF]
8​
[/td][td=bgcolor:#FFFFFF]
60​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
39​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td=bgcolor:#FFFFFF]
9​
[/td][td=bgcolor:#FFFFFF]
65​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
41​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td=bgcolor:#FFFFFF]
10​
[/td][td=bgcolor:#FFFFFF]
70​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
42​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td=bgcolor:#FFFFFF]
11​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
43​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td=bgcolor:#FFFFFF]
12​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
16
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
17
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet2[/td][/tr][/table]

AFTER

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][th]
G
[/th][th]
H
[/th][th]
I
[/th][th]
J
[/th][th]
K
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]S.No.[/td][td]
25689​
[/td][td]
365478​
[/td][td]
2569​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][td]
25698​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td][/td][td]
2564​
[/td][td]
2145​
[/td][td]
1425​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][td]
1478​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td=bgcolor:#FFFFFF]
1​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td=bgcolor:#FFFFFF]
2​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td=bgcolor:#FFFFFF]
3​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td=bgcolor:#FFFFFF]
4​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
[/td][td][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td=bgcolor:#FFFFFF]
5​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
9
[/td][td=bgcolor:#FFFFFF]
6​
[/td][td=bgcolor:#FFFFFF]
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
10
[/td][td=bgcolor:#FFFFFF]
7​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF]
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
11
[/td][td=bgcolor:#FFFFFF]
8​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
12
[/td][td=bgcolor:#FFFFFF]
9​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
13
[/td][td=bgcolor:#FFFFFF]
10​
[/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
14
[/td][td=bgcolor:#FFFFFF]
11​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF]
Yes​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
15
[/td][td=bgcolor:#FFFFFF]
12​
[/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td=bgcolor:#FFFFFF][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
16
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
17
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet2[/td][/tr][/table]

Code:
Sub Vishaal()
    Dim c As Long, lastCol As Long, r As Long
    Dim ws As Worksheet, c1 As Range, c2 As Range, c3 As Range
    Set ws = ActiveSheet
    
    lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
    
    For c = 2 To lastCol
        r = ws.Cells(ws.Rows.Count, c).End(xlUp).Row
        Set c1 = ws.Cells(4, c)
        Set c2 = ws.Cells(r, c)
        If r > 3 Then
            Set c3 = c2.Offset(-3)
            If c3.Row < 4 Then Set c3 = c1
            ws.Range(c1, c2).ClearContents
            ws.Range(c3, c2) = "Yes"
        End If
        
        Set c1 = Nothing
        Set c2 = Nothing
        Set c3 = Nothing
        
    Next c
End Sub
 
Upvote 0
Here is another one to try

Rich (BB code):
Sub YesLast4()
  Dim c As Long, fr As Long, lr As Long
  Const FirstDataRow As Long = 4
  
  For c = 2 To 5
    lr = Cells(Rows.Count, c).End(xlUp).Row
    If lr < FirstDataRow Then Exit For
    fr = lr - 3
    If fr < FirstDataRow Then fr = FirstDataRow
    Cells(fr, c).Resize(lr - fr + 1).Value = "Yes"
    If fr > FirstDataRow Then Cells(FirstDataRow, c).Resize(fr - FirstDataRow).ClearContents
  Next c
End Sub
 
Last edited:
Upvote 0
Thanks Yongle JI,

Its working for me,

Thanks for your help
 
Upvote 0
Hi, the above vba code are working fine for the above given data but when i am adding some coloumns and row, coloumn AtoCB and rows 1to25

The above code is not working

Help pls
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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