Good Afternoon
I've been working on the following macro trying to get all the values in a range for several weeks now. Im at a loss and have had several people help that have me to this point.
the code keeps erroring out and Im not certain of what to do next. Explanation of the macro: it takes the ip values and list them on sheet2 after expanding them by count
ie 10.10.10.1-10.10.10.3 would list 10.10.10.1 and 10.10.10.2 and 10.10.10.3 in column b of sheet2. if we have the values 10.10.10.1-10.10.11.1 would list all the values beginning at
10.10.10.1 thru 10.10.11.1
The code stops on the line show " N = N + 1" below
Any help would be greatly appreciated.
Thanks
xls input
Macro
Sub Expandit()
Dim W, S$(), N&, K&, V, L$(), R$(), A%, T$(3), B%, C%, D%
W = [Sheet1!A1].CurrentRegion.Value2
ReDim S(1 To Rows.Count, 1): S(1, 0) = W(1, 1): S(1, 1) = W(1, 2) ' get col1 and col2 into the array s
N = 1
For K = 2 To UBound(W)
For Each V In Split(W(K, 2), ",")
L = Split(V, "-")
If UBound(L) = 1 Then
R = Split(L(1), ".")
L = Split(L(0), ".")
If UBound(L) = 3 And UBound(R) = 3 Then
For A = L(0) To R(0)
T(0) = A
For B = -L(1) * (A = L(0) * 1) To IIf(A < R(0) * 1, 255, R(1))
T(1) = B
For C = -L(2) * (B = L(1) * 1) To IIf(B < R(1) * 1, 255, R(2))
T(2) = C
For D = -L(3) * (C = L(2) * 1) To IIf(C < R(2) * 1, 255, R(3))
T(3) = D
N = N + 1 '<-Error is happening here
S(N, 0) = W(K, 1)
S(N, 1) = Join(T, ".")
Next D, C, B, A
End If
Else
N = N + 1
S(N, 0) = W(K, 1)
S(N, 1) = V
End If
Next V, K
[Sheet2!A1:B1].Resize(N).Value2 = S
MsgBox "Completed"
End Sub
I've been working on the following macro trying to get all the values in a range for several weeks now. Im at a loss and have had several people help that have me to this point.
the code keeps erroring out and Im not certain of what to do next. Explanation of the macro: it takes the ip values and list them on sheet2 after expanding them by count
ie 10.10.10.1-10.10.10.3 would list 10.10.10.1 and 10.10.10.2 and 10.10.10.3 in column b of sheet2. if we have the values 10.10.10.1-10.10.11.1 would list all the values beginning at
10.10.10.1 thru 10.10.11.1
The code stops on the line show " N = N + 1" below
Any help would be greatly appreciated.
Thanks
xls input
Title | IPs |
Car | 10.218.68.3-11.218.68.3 |
Macro
Sub Expandit()
Dim W, S$(), N&, K&, V, L$(), R$(), A%, T$(3), B%, C%, D%
W = [Sheet1!A1].CurrentRegion.Value2
ReDim S(1 To Rows.Count, 1): S(1, 0) = W(1, 1): S(1, 1) = W(1, 2) ' get col1 and col2 into the array s
N = 1
For K = 2 To UBound(W)
For Each V In Split(W(K, 2), ",")
L = Split(V, "-")
If UBound(L) = 1 Then
R = Split(L(1), ".")
L = Split(L(0), ".")
If UBound(L) = 3 And UBound(R) = 3 Then
For A = L(0) To R(0)
T(0) = A
For B = -L(1) * (A = L(0) * 1) To IIf(A < R(0) * 1, 255, R(1))
T(1) = B
For C = -L(2) * (B = L(1) * 1) To IIf(B < R(1) * 1, 255, R(2))
T(2) = C
For D = -L(3) * (C = L(2) * 1) To IIf(C < R(2) * 1, 255, R(3))
T(3) = D
N = N + 1 '<-Error is happening here
S(N, 0) = W(K, 1)
S(N, 1) = Join(T, ".")
Next D, C, B, A
End If
Else
N = N + 1
S(N, 0) = W(K, 1)
S(N, 1) = V
End If
Next V, K
[Sheet2!A1:B1].Resize(N).Value2 = S
MsgBox "Completed"
End Sub
VBA Code:
Sub Expandit()
Dim W, S$(), N&, K&, V, L$(), R$(), A%, T$(3), B%, C%, D%
W = [Sheet1!A1].CurrentRegion.Value2
ReDim S(1 To Rows.Count, 1): S(1, 0) = W(1, 1): S(1, 1) = W(1, 2) ' get col1 and col2 into the array s
N = 1
For K = 2 To UBound(W)
For Each V In Split(W(K, 2), ",")
L = Split(V, "-")
If UBound(L) = 1 Then
R = Split(L(1), ".")
L = Split(L(0), ".")
If UBound(L) = 3 And UBound(R) = 3 Then
For A = L(0) To R(0)
T(0) = A
For B = -L(1) * (A = L(0) * 1) To IIf(A < R(0) * 1, 255, R(1))
T(1) = B
For C = -L(2) * (B = L(1) * 1) To IIf(B < R(1) * 1, 255, R(2))
T(2) = C
For D = -L(3) * (C = L(2) * 1) To IIf(C < R(2) * 1, 255, R(3))
T(3) = D
N = N + 1 '<-Error is happening here
S(N, 0) = W(K, 1)
S(N, 1) = Join(T, ".")
Next D, C, B, A
End If
Else
N = N + 1
S(N, 0) = W(K, 1)
S(N, 1) = V
End If
Next V, K
[Sheet2!A1:B1].Resize(N).Value2 = S
MsgBox "Completed"
End Sub
Last edited by a moderator: