-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnexure-B.bas
103 lines (97 loc) · 3.52 KB
/
Annexure-B.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Attribute VB_Name = "Module1"
Sub FinalOutput()
Dim LngCol As Long
Dim intLastRow As Integer
' Duplicate Sheet as backup
For Each ws In Worksheets
If ws.Name = "Sheet2_Backup" Then
Application.DisplayAlerts = False
Sheets("Sheet2_Backup").Delete
Application.DisplayAlerts = True
ElseIf ws.Name = "Result_Sheet" Then
Application.DisplayAlerts = False
Sheets("Result_Sheet").Delete
Application.DisplayAlerts = True
End If
Next
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Sheet2").Copy _
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Name = "Sheet2_Backup"
Application.DisplayAlerts = True
ThisWorkbook.Sheets("Sheet2").Select
For LngCol = 2 To ColNumber("IJV")
' Step -1
Worksheets("Sheet2").Range(ColLetter(LngCol + 1) & "2:" & ColLetter(LngCol + 1) & FindLastRow(LngCol)).Value = Worksheets("Sheet2").Cells(1, LngCol).Value
' Step -2
If LngCol > 2 Then
Worksheets("Sheet2").Range("A" & FindLastRow(1) + 1 & ":C" & FindLastRow(1) + FindLastRow(LngCol + 1) - 1).Value = Worksheets("Sheet2").Range(ColLetter(LngCol - 1) & "2:" & ColLetter(LngCol + 1) & FindLastRow(LngCol + 1)).Value
End If
LngCol = LngCol + 3
Next
Worksheets("Sheet2").Range("A1").Value = "Indication"
Worksheets("Sheet2").Range("B1").Value = "Value"
Worksheets("Sheet2").Range("C1").Value = "Drug Name"
Worksheets("Sheet2").Range("D1:IJV500").ClearContents
Range("A1:C1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.349986266670736
.PatternTintAndShade = 0
End With
Selection.Font.Bold = True
Range("A1:C" & FindLastRow(1)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Columns("A:C").Select
Columns("A:C").EntireColumn.AutoFit
Sheets("Sheet2").Name = "Result_Sheet"
Sheets("Sheet2_Backup").Name = "Sheet2"
End Sub
Function FindLastRow(intCol) As Long
FindLastRow = Cells(Rows.Count, intCol).End(xlUp).Row
End Function
Function ColLetter(ColNumber As Long) As String
ColLetter = Split(Cells(1, ColNumber).Address, "$")(1)
End Function
Function ColNumber(ColumnLetter As String) As Integer
ColNumber = Range(ColumnLetter & 1).Column
End Function