vba 在 MS.Excel 中生成特定范围的 IP 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28578362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:16:08  来源:igfitidea点击:

Generate a specific range of IP address in MS.Excel

excelexcel-vbaexcel-formulavba

提问by Saad Awan

I want to generate a specific range of IP from 192.168.1.0to 192.168.255.255

我想生成IP的特定范围192.168.1.0,以192.168.255.255

How can I do that job in Microsoft Excel?

我如何在 Microsoft Excel 中完成这项工作?

I used these formulas, but not work for all range of IP address:

我使用了这些公式,但不适用于所有 IP 地址范围:

Excel IP Addresses Increment the Third Octet
="10.1."&ROWS($A:A1)&".1"
Excel IP Addresses Increment the Fourth Octet
="10.1.1."&ROWS($A:A1)

回答by

Your starting IP address is 10.1.1.1. That is 0A010101 IN HEX. Put that in a cell, let's say A2. Put this formula in B2,

您的起始 IP 地址是 10.1.1.1。那是十六进制的 0A010101。把它放在一个单元格中,比如说A2。把这个公式放在B2中,

=HEX2DEC(LEFT(A2, 2))&"."&HEX2DEC(MID(A2, 3, 2))&"."&HEX2DEC(MID(A2, 5, 2))&"."&HEX2DEC(RIGHT(A2, 2))

Now put this formula in A3,

现在把这个公式放在A3中,

=DEC2HEX(HEX2DEC(A2)+1, 8)

Copy the formula from B2 to B3 then fill A3:B3 down as far as you want.

将公式从 B2 复制到 B3,然后根据需要向下填充 A3:B3。

????IP Addresses

???IP地址

回答by robotik

here's an elementary solution

这是一个基本的解决方案

in A1put 1000 for starting at 1.0or 0 for srating at 0.0

输入A11000 用于开始1.0或 0 用于评分0.0

in A2put =A1+IF(MOD(A1,1000)<255,1,745)

A2=A1+IF(MOD(A1,1000)<255,1,745)

in B1put ="192.168." & QUOTIENT(A1,1000) & "." & MOD(A1,1000)(of course the "192.168."part is your first two octet, modify it to taste)

B1认沽="192.168." & QUOTIENT(A1,1000) & "." & MOD(A1,1000)(当然"192.168."部分是你的前两个八位字节,它修改口味)

copy the formula from B1to B2then fill A2:B2down and voilà.

复制公式从B1B2然后填写A2:B2和voilà。