Commit de63e6f7 authored by Dionysis Dimakopoulos's avatar Dionysis Dimakopoulos
Browse files

CSV dummy file used in all scenarios

BAS files containing VBA code for creation and import of CSV file
XLS file containing worksheet with formulas used to generate random data for CSV file
Updated README
parent 41e0641f
# Covid-19 Excel error analysis
This repository contains the following files
* covid_test_data.csv<br>
This is the dummy CSV file we created to test several scenarios that might have led to the COVID-19 Excel error by NHS Track-and-trace
* modCSVCreator.bas<br>
This file contains the createCovidTestsCSV() VBA subroutine that was used to create the dummy CSV file above. In order to run it you need the xls file below that contains a worksheet containing random data generated by Excel formulas.
* RandomCSVCreator.xls<br>
This Excel workbook contains a worksheet with random data used by modCSVCreator.bas to add in the dummy CSV file.
* modImportLargeCSV.bas<br>
This Excel VBA module contains the subroutine used to test importing a large CSV using VBA.
This diff is collapsed.
Attribute VB_Name = "modCSVCreator"
Option Explicit
'Create a new COVID-19 dummy CSV file by running this subroutine
'Download file RandomCSVCreator.xls which contains worksheet shRandomData
Sub createCovidTestsCSV()
Dim filename As String
Dim rowsStored As Long, rowsReturned As Long
filename = getFilename
Open filename For Output As #1
Debug.Print "CSV creation started at " & Time
rowsStored = 0
Print #1, getCSVPayload(rowsStored, rowsReturned)
rowsStored = rowsStored + rowsReturned
Debug.Print rowsStored
Loop Until rowsStored > 2 ^ 20
Close #1
Debug.Print "CSV creation ended at " & Time
End Sub
Function getFilename()
getFilename = Application.GetSaveAsFilename
End Function
Function getCSVPayload(rowsStored As Long, ByRef rowsReturned As Long) As String
Dim randomData As Variant
Dim currentRng As Range
Dim i As Long, j As Integer
Dim csvRows() As String, csvRow(1 To 8) As String
Set currentRng = shRandomData.Range("A1").CurrentRegion
If rowsStored > 0 Then
Set currentRng = shRandomData.Range("A1").CurrentRegion.Offset(1, 0).Resize(currentRng.Rows.Count - 1)
End If
randomData = currentRng.Value
ReDim csvRows(1 To currentRng.Rows.Count)
For i = LBound(csvRows, 1) To UBound(csvRows, 1)
For j = 1 To 8
csvRow(j) = randomData(i, j)
Next j
csvRows(i) = Join(csvRow, ",")
Next i
getCSVPayload = Join(csvRows, vbNewLine)
rowsReturned = currentRng.Rows.Count
End Function
Attribute VB_Name = "modImportLargeCSV"
Option Explicit
Sub ImportLargeCSVTest()
Dim ImpRng As Range
Dim Filename As String
Dim r As Long
Dim Data, parts
Dim i As Integer
Set ImpRng = ActiveCell
On Error Resume Next
Filename = "C:\Users\ddimak\Documents\courses\VBA Part 3\National_Statistics_Postcode_Lookup_UK.csv"
Open Filename For Input As #1
If Err <> 0 Then
MsgBox "Not found: " & Filename, vbCritical, "ERROR"
Exit Sub
End If
On Error GoTo 0
r = 0
Do Until EOF(1)
Line Input #1, Data
parts = Split(Data, ",")
Range(ImpRng.Offset(r, 0), ImpRng.Offset(r, UBound(parts))).Value = parts
r = r + 1
Close #1
End Sub
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment