Hi,
I have the following macro which replaces the data in cells that are not blank within several columns in an Excel table, however the macro takes more than two hours to run due to the size of the table (40,000 rows and 50 columns). Is there a more efficient code I could use that would achieve the same result faster?
Sub PersonalDetails()
With ThisWorkbook.Worksheets("ActiveWorkers")
For a = 1 To 10000
If Range("Table145[Emergency Contacts]")(a) > 0 Then
If Range("Table145[Emergency Contacts]")(a) = "" Then
Exit Sub
End If
Range("Table145[Emergency Contacts]")(a) = "X"
End If
Next
For b = 1 To 10000
If Range("Table145[Home Address]")(b) > 0 Then
If Range("Table145[Home Address]")(b) = "" Then
Exit Sub
End If
Range("Table145[Home Address]")(b) = "X"
End If
Next
For c = 1 To 10000
If Range("Table145[Home Phone]")(c) > 0 Then
If Range("Table145[Home Phone]")(c) = "" Then
Exit Sub
End If
Range("Table145[Home Phone]")(c) = "X"
End If
Next
For d = 1 To 10000
If Range("Table145[Mobile Phone Number]")(d) > 0 Then
If Range("Table145[Mobile Phone Number]")(d) = "" Then
Exit Sub
End If
Range("Table145[Mobile Phone Number]")(d) = "X"
End If
Next
For e = 1 To 10000
If Range("Table145[Email - Home]")(e) > 0 Then
If Range("Table145[Email - Home]")(e) = "" Then
Exit Sub
End If
Range("Table145[Email - Home]")(e) = "X"
End If
Next
End With
MsgBox "Finished replacing " & CStr(dblCnt) & " items", vbOKOnly, "Complete"
End Sub
I have the following macro which replaces the data in cells that are not blank within several columns in an Excel table, however the macro takes more than two hours to run due to the size of the table (40,000 rows and 50 columns). Is there a more efficient code I could use that would achieve the same result faster?
Sub PersonalDetails()
With ThisWorkbook.Worksheets("ActiveWorkers")
For a = 1 To 10000
If Range("Table145[Emergency Contacts]")(a) > 0 Then
If Range("Table145[Emergency Contacts]")(a) = "" Then
Exit Sub
End If
Range("Table145[Emergency Contacts]")(a) = "X"
End If
Next
For b = 1 To 10000
If Range("Table145[Home Address]")(b) > 0 Then
If Range("Table145[Home Address]")(b) = "" Then
Exit Sub
End If
Range("Table145[Home Address]")(b) = "X"
End If
Next
For c = 1 To 10000
If Range("Table145[Home Phone]")(c) > 0 Then
If Range("Table145[Home Phone]")(c) = "" Then
Exit Sub
End If
Range("Table145[Home Phone]")(c) = "X"
End If
Next
For d = 1 To 10000
If Range("Table145[Mobile Phone Number]")(d) > 0 Then
If Range("Table145[Mobile Phone Number]")(d) = "" Then
Exit Sub
End If
Range("Table145[Mobile Phone Number]")(d) = "X"
End If
Next
For e = 1 To 10000
If Range("Table145[Email - Home]")(e) > 0 Then
If Range("Table145[Email - Home]")(e) = "" Then
Exit Sub
End If
Range("Table145[Email - Home]")(e) = "X"
End If
Next
End With
MsgBox "Finished replacing " & CStr(dblCnt) & " items", vbOKOnly, "Complete"
End Sub