Hello,
I'm a java backend developer (spring an so on) I know nothing about visual basic scripts in Excel, at work they gave me a task to speed up this script (ROTFL),
The execution time is about 6-8 hours. I read that accessing data from a loop is a bad practice, Please help me on how to speed up this (using regions perhaps ? ), Thank you.
thank you very very much
I'm a java backend developer (spring an so on) I know nothing about visual basic scripts in Excel, at work they gave me a task to speed up this script (ROTFL),
The execution time is about 6-8 hours. I read that accessing data from a loop is a bad practice, Please help me on how to speed up this (using regions perhaps ? ), Thank you.
VBA Code:
Sub CREATE_RELATIONSHIPS(ByRef wb As Workbook)
Dim sh As Worksheet
Dim rw As Variant
Dim RowCount As Integer
Dim PK_T As String, PK_C As String, FK_T As String, FK_C As String
Const CREATING_RELATION_CONST = "Creating Relationship "
Dim start As Double
Dim realationsCounter As Long
start = Timer
RowCount = 0
Set sh = wb.Sheets("Relations")
For Each rw In sh.Rows
If sh.Cells(rw.Row, 1).Value = "" Then
Exit For
End If
If RowCount >= 1 Then
FK_T = sh.Cells(rw.Row, 1).Value
FK_C = sh.Cells(rw.Row, 2).Value
PK_T = sh.Cells(rw.Row, 3).Value
PK_C = sh.Cells(rw.Row, 4).Value
Debug.Print CREATING_RELATION_CONST, FK_T, FK_C, PK_T, PK_C
'On Error Resume Next
wb.Model.ModelRelationships.Add wb.Model.ModelTables(FK_T).ModelTableColumns(FK_C), wb.Model.ModelTables(PK_T).ModelTableColumns(PK_C)
realationsCounter = realationsCounter + 1
'If Err Then
' Debug.Print "Error"
'Else
' Debug.Print "Created relationship"
'End If
End If
RowCount = RowCount + 1
Next rw
Debug.Print realationsCounter, " relations created."
End Sub
thank you very very much