-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatBookstoreList.vbs
409 lines (316 loc) · 12.6 KB
/
FormatBookstoreList.vbs
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
Sub FormatBookstoreList()
'This macro formats our textbook vendor's export of all textbooks and courses for next semester.
'There are a lot of columns that could contain important information, but are not helpful at-a-glance, so this macro hides them.
'After formating this into a readable state, I run Princeton's Excel Alma Lookup tool (https://github.com/pulibrary/ExcelAlmaLookup/#readme) to see what textbooks we have in our catalog (and where they are)
'Part 1: Set up the Sheet'
'Set the active sheet as a variable for easier reference
Dim ws As Worksheet
Set ws = ActiveSheet
Dim cell As Range
' Check if a filter is currently applied
If ws.AutoFilterMode Then
' Remove the filter
ws.AutoFilterMode = False
End If
'Rename sheet with B5 (semester)'
Worksheets(1).Name = ws.Cells(5, 2).Value
'Delete rows that don't have data in column F'
Do While ws.Cells(1, 6).Value = ""
ws.Rows(1).Delete
Loop
'Part 2: Find all of the columns we're going to use and put them in the right order using X = X+1'
'School, Department, Course Code, Course Title, SKU, Digital Available, Note for Bookstore, Price at Time of Adoption, Submitter, Submitter Email, Date Submitted'
'Create variable X as integer'
Dim X As Long
X = 3
'Find and move the "School" column'
Dim Col As Long
Col = ws.Rows(1).Find("School").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Department").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Course Code").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Course Title").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
If InStr(1, ws.Cells(1, X).Value, "Course Title") > 0 Then
ws.Cells(1, X).Value = "Course Name"
End If
'The book column Title and Course Title were confusing each other so I had it print a MsgBox so I could see which column it was picking up here
'Dim aaa As String
'aaa = ws.Cells(1, X).Value
'MsgBox aaa, vbOKOnly
'X = X + 1
Col = ws.Rows(1).Find("SKU").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Digital Available").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Price").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Note for Bookstore").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Submitter").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Submitter Email").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Date Submitted").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Date Submitted").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Dim DeleteThese As Long
DeleteThese = X
Col = ws.Rows(1).Find("Section").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Instructor").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("ISBN").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
'Now that I've renamed Course Title this line is probably unnecessary but why change something that's working?
Col = ws.Rows(1).Find(What:="Title", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False).Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
If ws.Cells(1, X).Value = "Title" Then
ws.Cells(1, X).Value = "Title"
End If
X = X + 1
Col = ws.Rows(1).Find("Author").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Edition").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
Col = ws.Rows(1).Find("Type").Column
If Col <> X Then
ws.Columns(Col).Cut
ws.Columns(X).Insert Shift:=xlToRight
End If
X = X + 1
'Part 3: Assign Variables to all of the new column locations'
Dim ISBN As Long
ISBN = ws.Rows(1).Find("ISBN").Column
Dim SKU As Long
SKU = ws.Rows(1).Find("SKU").Column
Dim Title As Long
Title = ws.Rows(1).Find("Title").Column
Dim NUM As Long
NUM = ws.Rows(1).Find("Not Using Materials").Column
Dim Author As Long
Author = ws.Rows(1).Find("Author").Column
Dim Section As Long
Section = ws.Rows(1).Find("Section").Column
Dim Edition As Long
Edition = ws.Rows(1).Find("Edition").Column
Dim RType As Long
RType = ws.Rows(1).Find("Type").Column
Dim Instructor As Long
Instructor = ws.Rows(1).Find("Instructor").Column
'Part 4: Delete a bunch of stuff that we are never going to have in our Alma'
'lastRow'
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
'Use 1 for loop to delete the row if it contains any of the following:'
'Deleting the row would change the row number, and multiple "next i" statements are invalid, so we are going to clear contents instead'
For i = 2 To lastRow
If ws.Cells(i, Edition).Value = "Not Available" Then
ws.Cells(i, Edition).Value = "N/A"
End If
If ws.Cells(i, RType).Value = "RECOMMENDED" Then
ws.Cells(i, RType).Value = "Recom."
ElseIf ws.Cells(i, RType).Value = "REQUIRED" Then
ws.Cells(i, RType).Value = "Required"
ElseIf ws.Cells(i, RType).Value = "Not Available" Then
ws.Cells(i, RType).Value = "N/A"
End If
If Left(ws.Cells(i, ISBN).Value, "3") = "281" Then
ws.Rows(i).ClearContents
ElseIf ws.Cells(i, NUM).Value = "Yes" Then
ws.Rows(i).ClearContents
ElseIf InStr(1, ws.Cells(i, Title), "FROM INQUIRY") > 0 Then
ws.Rows(i).ClearContents
ElseIf InStr(1, ws.Cells(i, Title), "CENGAGE UNLIMITED") > 0 Then
ws.Rows(i).ClearContents
ElseIf InStr(1, LCase(ws.Cells(i, Title)), "binghamton writes") > 0 Then
ws.Rows(i).ClearContents
ElseIf InStr(1, LCase(ws.Cells(i, Title)), "student lab notebook") > 0 Then
ws.Rows(i).ClearContents
ElseIf InStr(1, LCase(ws.Cells(i, Author)), "iclicker") > 0 Then
ws.Rows(i).ClearContents
ElseIf InStr(1, LCase(ws.Cells(i, Author)), "i-clicker") > 0 Then
ws.Rows(i).ClearContents
ElseIf Left(ws.Cells(i, Title).Value, "19") = "DAVVERO 1: 12-MONTH" Then
ws.Rows(i).ClearContents
ElseIf Left(ws.Cells(i, Title).Value, "18") = "DAVVERO 1: 6-MONTH" Then
ws.Rows(i).ClearContents
Else
End If
Next i
'Sort the data so that it is usable'
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=ws.Columns(Author), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=ws.Columns(Section), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=ws.Columns(ISBN), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("A:BB")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Part 5: Clean up the data'
'Delete Columns: Store, Not Using Materials, Campus, Publisher, Condition, OER, OER+'
If ws.Cells(1, 1).Value = "Store" Then
ws.Columns(1).EntireColumn.Delete
End If
Col = ws.Rows(1).Find("Not Using Materials").Column
ws.Columns(Col).EntireColumn.Delete
Col = ws.Rows(1).Find("Campus").Column
ws.Columns(Col).EntireColumn.Delete
Col = ws.Rows(1).Find("Publisher").Column
ws.Columns(Col).EntireColumn.Delete
Col = ws.Rows(1).Find("Condition").Column
ws.Columns(Col).EntireColumn.Delete
Col = ws.Rows(1).Find("OER").Column
ws.Columns(Col).EntireColumn.Delete
Col = ws.Rows(1).Find("OER+").Column
ws.Columns(Col).EntireColumn.Delete
'Fix ISBN and SKU'
ISBN = ws.Rows(1).Find("ISBN").Column
Columns(ISBN).NumberFormat = "0"
SKU = ws.Rows(1).Find("SKU").Column
Columns(SKU).NumberFormat = "0"
'Hide columns we want to keep but not see (School, Department, Course Code, Course Title, SKU, Digital Available, Note for Bookstore, Price at Time of Adoption, Submitter, Submitter Email, Date Submitted)'
'Selection.EntireColumn.Hidden = True'
Dim School As Long
School = ws.Rows(1).Find("School").Column
ws.Columns(School).Select
Selection.EntireColumn.Hidden = True
Dim Dept As Long
Dept = ws.Rows(1).Find("Department").Column
ws.Columns(Dept).Select
Selection.EntireColumn.Hidden = True
Dim CourseCode As Long
CourseCode = ws.Rows(1).Find("Course Code").Column
ws.Columns(CourseCode).Select
Selection.EntireColumn.Hidden = True
Dim CourseN As Long
CourseN = ws.Rows(1).Find("Course Name").Column
ws.Columns(CourseN).Select
Selection.EntireColumn.Hidden = True
ws.Columns(SKU).Select
Selection.EntireColumn.Hidden = True
Dim Digital As Long
Digital = ws.Rows(1).Find("Digital Available").Column
ws.Columns(Digital).Select
Selection.EntireColumn.Hidden = True
Dim NoteB As Long
NoteB = ws.Rows(1).Find("Note for Bookstore").Column
ws.Columns(NoteB).Select
Selection.EntireColumn.Hidden = True
Dim Price As Long
Price = ws.Rows(1).Find("Price at Time of Adoption").Column
ws.Columns(Price).Select
Selection.EntireColumn.Hidden = True
Dim Submitter As Long
Submitter = ws.Rows(1).Find("Submitter").Column
ws.Columns(Submitter).Select
Selection.EntireColumn.Hidden = True
Dim SubmitterE As Long
SubmitterE = ws.Rows(1).Find("Submitter Email").Column
ws.Columns(SubmitterE).Select
Selection.EntireColumn.Hidden = True
Dim DateS As Long
DateS = ws.Rows(1).Find("Date Submitted").Column
ws.Columns(DateS).Select
Selection.EntireColumn.Hidden = True
'Selection.EntireColumn.Hidden = True'
'Part 6: Format the sheet for viewing and printing'
ISBN = ws.Rows(1).Find("ISBN").Column
Title = ws.Rows(1).Find("Title").Column
Author = ws.Rows(1).Find("Author").Column
Section = ws.Rows(1).Find("Section").Column
Edition = ws.Rows(1).Find("Edition").Column
RType = ws.Rows(1).Find("Type").Column
Instructor = ws.Rows(1).Find("Instructor").Column
'Make it a table'
ws.ListObjects.Add(xlSrcRange, ws.Range("A1").CurrentRegion, , xlYes).TableStyle = "TableStyleLight18"
'Autofit stuff'
ws.Columns(Title).ColumnWidth = 42
ws.Columns(Author).ColumnWidth = 28
ws.Columns(Edition).ColumnWidth = 8
ws.Columns(RType).ColumnWidth = 7
ws.Columns(ISBN).ColumnWidth = 13.2
ws.Columns(Instructor).ColumnWidth = 17
ws.Columns(Section).ColumnWidth = 12.86
'Font size'
'Center, left, right stuff'
ws.Columns(Edition).HorizontalAlignment = xlCenter
'This sheet is 5,000 items long at this point (down from 7,000!) so I do not format it for printing'
End Sub