本文介绍了用范围替换序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到一个单元格中的序号,并将其替换为一个范围?
例如:

How can I find sequential numbers in a cell, and replace them with a range?
For example:

更改:

收件人:

数字已经排序,即按升序排列.

The numbers are already sorted, i.e. in increasing order.

谢谢.

推荐答案

我想研究一个有趣的问题,而不必遍历序列(首先需要排序)来检查顺序构建

An interesting question that I wanted to look at do without looping through a sequence (which would need sorting first) checking for sequential builds

此功能

  1. 将字符串强制为范围地址
  2. 使用 Union 将连续的行分组在一起
  3. 操纵字符串以删除列标识符

循环不是必需的,较短的版本!

Function NumOut(strIn As String) As String
Dim rng1 As Range  
Set rng1 = Range("A" & Join(Split(Application.Trim([a1]), ", "), ",A"))
'force the range into areas rather than cells
Set rng1 = Union(rng1, rng1)
NumOut = Replace(Replace(Replace(rng1.Address, "$A$", vbNullstring), ": ", "-"), ",", ", ")
End Function

这篇关于用范围替换序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:31