-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule1.bas
More file actions
267 lines (210 loc) · 7.69 KB
/
Module1.bas
File metadata and controls
267 lines (210 loc) · 7.69 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
Attribute VB_Name = "Module1"
Public Compa As Worksheet
Public Cont As Boolean 'Checker if there is an item in clipboard
Public PQq As Boolean
Public Cleardata As Boolean
Public MeterType As String
Public MeterName As String
Public StatAdd As String
Public eventE As Integer
'--------------------------Coords
Public Rs As Integer
Public Cs As Integer
Public Rz As Integer
Public Cz As Integer
Private Sub MeterCheck()
MeterType = "" 'Making it empty first
MeterType = ActiveWorkbook.Sheets("Main").Range(ActiveCell.Offset(, 1).Address).Value
End Sub
Public Sub ImpoW()
'------------------------------------------- Initialization
Dim CsvF As String 'csv dir
Dim R0 As Integer
Dim C0 As Integer
Dim csvWB As Object 'csv obj
Dim exApp As Object
Set exApp = CreateObject("Excel.Application." & CLng(Application.Version))
'-------------------------------------------Log Verification
If ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Wave Only" Then 'PQ with Wave
Call ImpoP
PQq = True
Exit Sub
End If
'------------------------------------------- Opening File
CsvF = Application.GetOpenFilename()
If CsvF = "False" Then
MsgBox "No Selected File"
Cont = False
Exit Sub
End If
If (Right(CsvF, 4)) <> ".csv" And (Right(CsvF, 4)) <> "xlsx" Then
MsgBox "Invalid File"
Cont = False
Exit Sub
End If
Set csvWB = exApp.Workbooks.Open(CsvF)
csvWB.ActiveSheet.Activate
csvWB.ActiveSheet.Range("A1").Activate
'----------------------------------------- Copying File
R0 = csvWB.ActiveSheet.UsedRange.Rows.Count
C0 = csvWB.ActiveSheet.UsedRange.Columns.Count
If C0 = 17 And ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "" Then 'Waveform
csvWB.ActiveSheet.Range("A1", Cells(R0, C0).Address()).Copy
Rs = R0
Cs = C0
ElseIf C0 = 7 And ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "" Then 'PQ without Wave
MsgBox "Please import Waveform Logs first."
Cont = False
csvWB.Close
exApp.Quit
ActiveWorkbook.Sheets("Main").Activate
Exit Sub
Else
MsgBox "Invalid log type."
Cont = False
End If
csvWB.Close
exApp.Quit
Cont = True
End Sub
Public Sub ImpoP()
'------------------------------------------- Initialization
Dim CsvF1 As String 'csv dir
Dim R1 As Integer
Dim C1 As Integer
Dim csvWB1 As Object 'csv obj
Dim exApp1 As Object
Set exApp1 = CreateObject("Excel.Application." & CLng(Application.Version))
'------------------------------------------- Opening File
CsvF1 = Application.GetOpenFilename()
If CsvF1 = "False" Then
MsgBox "No Selected File"
Cont = False
Exit Sub
End If
If (Right(CsvF1, 4)) <> ".csv" And (Right(CsvF1, 4)) <> "xlsx" Then
MsgBox "Invalid File"
Cont = False
Exit Sub
End If
Set csvWB1 = exApp1.Workbooks.Open(CsvF1)
csvWB1.ActiveSheet.Activate
csvWB1.ActiveSheet.Range("A1").Activate
Call MeterCheck
'----------------------------------------- Copying File
R1 = csvWB1.ActiveSheet.UsedRange.Rows.Count
C1 = csvWB1.ActiveSheet.UsedRange.Columns.Count
If C1 = 7 And ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Wave Only" Then 'PQ with Wave already
csvWB1.ActiveSheet.Range("A1", Cells(R1, C1).Address()).Copy
Rz = R1
Cz = C1
ElseIf C1 = 17 And ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Wave Only" Then 'Wave again
MsgBox "This is another waveform logs."
Cont = False
Exit Sub
Else
MsgBox "This is not PQ Log."
Cont = False
End If
csvWB1.Close
exApp1.Quit
Cont = True
End Sub
Public Sub WPaster()
Set Compa = ActiveWorkbook.Sheets(MeterName)
Dim sRange As Range
'------------------- Pasting
Compa.Activate
Compa.Range("J2").Activate
Compa.Paste
Compa.Range("J2", Cells(Rs + 1, 27).Address()).Sort Key1:=Range("J2"), Order1:=xlAscending, Header:=xlYes
Compa.Range("J1").Value = "Wave Log#:"
'Compa.Range("K1").Value = Cs
Compa.Range("K1").Value = Rs
Compa.Range("P1").Value = "Meter Type"
Compa.Range("Q1").Value = MeterType
'------------------- Bordering
Set sRange = Compa.Range("J2", Cells(Rs + 1, 26).Address())
For Each iCells In sRange
iCells.BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThin
Next iCells
Compa.Range("J2", Cells(Rs + 1, 26).Address()).BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThick
Compa.Range("J2", Cells(2, 26).Address()).BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThick
'--------------------------------------Changing Status in Main sheet
ActiveWorkbook.Sheets("Main").Activate
ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Wave Only"
End Sub
Public Sub PPaster()
Dim Pp
Dim Rx As Integer
Dim tRange As Range
Set Pp = ActiveWorkbook.Sheets(MeterName)
'Cx = Pp.Range("K1").Value
Rx = Pp.Range("K1").Value
'------------------- Pasting
If Rx <> 0 Then
Pp.Activate
Pp.Range(Cells(Rx + 3, 10).Address()).Activate
Pp.Paste
Pp.Range(Cells(Rx + 3, 10).Address(), Cells(Rx + Rz + 2, 10 + Cz).Address()).Sort Key1:=Range(Cells(Rx + 3, 10).Address()), Order1:=xlAscending, Header:=xlYes
Pp.Range("M1").Value = "PQ Log #:"
'Pp.Range("N1").Value = Cz
Pp.Range("N1").Value = Rz
End If
'------------------- Bordering
Set tRange = Pp.Range(Cells(Rx + 3, 10).Address(), Cells(Rx + Rz + 2, 9 + Cz).Address())
For Each iCells In tRange
iCells.BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThin
Next iCells
Pp.Range(Cells(Rx + 3, 10).Address(), Cells(Rx + Rz + 2, 9 + Cz).Address()).BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThick
Pp.Range(Cells(Rx + 3, 10).Address(), Cells(Rx + 3, 9 + Cz).Address()).BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlThick
Pp.Columns("J:Z").HorizontalAlignment = xlCenter
Pp.Columns("J:Z").AutoFit
'--------------------------------------Changing Status in Main sheet
ActiveWorkbook.Sheets("Main").Activate
If Cz = 17 Then
MsgBox "This is also a waveform"
ActiveWorkbook.Sheets("Main").Activate
Exit Sub
ElseIf ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Wave Only" And Rx <> 0 Then
ActiveWorkbook.Sheets("Main").Range(StatAdd).Value = "Stored"
End If
End Sub
Public Sub Clears()
Dim StatsAdd As String
If Intersect(ActiveCell, Range("C20:C35")) Is Nothing Then
MsgBox "Select the Meter Name to proceed. Try Again."
Exit Sub
Else
If ActiveCell.Offset(, 2) = "" Then
'MsgBox "Nothing to Clear"
Exit Sub
End If
End If
StatsAdd = ActiveCell.Offset(, 2).Address()
For Each shts In ThisWorkbook.Worksheets 'Check if the worksheet is already existing
If shts.Name = ActiveCell.Value Then
Set Compa = ActiveWorkbook.Sheets(ActiveCell.Value)
Compa.Activate
Compa.UsedRange.ClearContents
Compa.UsedRange.ClearFormats
Cleardata = False
Exit For
End If
Next shts
ActiveWorkbook.Sheets("Main").Activate
ActiveWorkbook.Sheets("Main").Range(StatsAdd).Value = ""
ActiveWorkbook.Sheets("Main").Range(StatsAdd).Offset(, 1).Value = ""
End Sub