Im looking for someone who can improve my code, because at the moment it takes 4 minutes to execute. I'm new to VBA so it's probably bad coding. Normally if you are good in VBA you will understand the code, if not please ask more information.
Here is the code:
Sub InternExtern()
Dim source, addrescell, destination As Range
Dim Sourcevalue As String
For Each source In Range("E6", Range("E" & Rows.Count).End(xlUp))
If source.Value <> "" Then
For Each addrescell In Range("address_table_names").Rows
If addrescell.Cells(1).Value <> "" And InStr(source.Offset(0, 23).Value, "Extern") = 0 Then
SourceName = addrescell.Cells(1).Value
Sourcevalue = addrescell.Cells(1, 4).Value
If InStr(UCase(source), UCase(SourceName)) <> 0 Then
If InStr(Sourcevalue, "10.") <> 0 Or InStr(Sourcevalue, "192.168.") <> 0 Or IsInternal(addrescell.Offset(0, 3).Value) Then
source.Offset(0, 23) = "Intern"
Else: source.Offset(0, 23) = "Extern"
End If
End If
If InStr(source, "-ext-") <> 0 Or InStr(source, "any") <> 0 Or InStr(source, "-EXT-") <> 0 Then
source.Offset(0, 23) = "Extern"
End If
If InStr(source, "any") <> 0 And InStr(source.Offset(0, -1).Value, "FW-Peering") = 0 Then
source.Offset(0, 23) = "Intern"
End If
End If
Next addrescell
End If
Next source
Some information you need to know:
The IsInternal
function, is very basic and short, its not the reason why the code takes so long to execute.
the range in E6
counts more than 1000 rows.
the "address_table_names
" name range is in another sheet and contains +- 800 rows.
If there are other things you don't understand, please ask.