Maximum Rows per page

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Good afternoon All
i've been working on the following excel macro code trying to get only so many rows per worksheet. (25) I have a workbook with one sheet containing the following information

ProdIPs
A10.10.10.0-10.10.10.255
B192.168.1.1-192.168.1.255

When the following macro runs it puts all the information into one sheet(sheet2).
I need it to create new sheets with a max row count of 25 in each new sheet.
All the output is done at the end of the macro where it shows sheet2

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)
N = 1
imax = 10000000
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
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
End Sub


Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
VBA Code:
     ....
     Next V, K
     [Sheet2!A1:B1].Resize(N).Value2 = S

     For i = 1 To N Step 25                                     'divide N in portions of max 25
          arr = WorksheetFunction.Sequence(Application.Min(25, N - i + 1), 1, i)     ' a 2D-array in the sequence i, i+1, i+2, ...., i+24 (or less then 24 in the last run)  ---> sequence = only in excel 365 and 2021 !!!
          Sheets.Add after:=Sheets(Sheets.Count)                'add sheet after all the others
          ActiveSheet.Range("A1").Resize(UBound(arr), 2).Value2 = Application.Index(S, arr, Array(1, 2))     'write <=25 lines * 2 columns
     Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,216,051
Messages
6,128,503
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top