Opening new worksheets based on entries
Assuming the IP's are column 1 and sorted on the 3rd octet:
Sub copyIP()
Dim sh As Worksheet, Startrow As Long
Dim lastrow As Long, v1, v, i As Long
Set sh = Worksheets("Data")
Startrow = 1
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row
ReDim v1(0 To 3)
v1(2) = ""
i = 1
For i = 1 To lastrow
v = Split(sh.Cells(i, 1), ".")
If v(2) < v1(2) And i < 1 Then
Worksheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = v1(2)
sh.Range(sh.Rows(Startrow), sh.Rows(i - 1)).Copy _
ActiveSheet.Range("A1")
Startrow = i
End If
v1 = v
Next i
Worksheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = v1(2)
sh.Range(sh.Rows(Startrow), sh.Rows(lastrow)).Copy _
ActiveSheet.Range("A1")
End Sub
--
Regards,
Tom Ogilvy
"RomanR" wrote:
Hi all,
Got another question about the macro I'm writing. It's an IP address
database, the IPs are all listed in column A as such:
111.222.32.4
111.222.32.5
111.222.32.66
111.222.37.1
111.222.37.2
111.222.37.3
111.222.38.13
111.222.38.24
111.222.38.35
They are class B adresses, and the 3rd octet changes about 220 times
throughout the text files (here I show it change from 32 to 37 to 38).
I need to implement some steps which would open a new worksheet for
every new 3rd octet in the text file. I know I will end up with a
couple hundred sheets, but it's what my boss wants.
Any ideas are more than welcome.
Thanks in advance,
Roman
|