我有一个很大的范围,我需要找到长度在4到6位之间的所有数字 我知道我可以使用正则表达式,但我不想循环每个单元格并检查所有单元格。
我需要的是选择范围复制并粘贴到记事本中并复制回变量 通过这种方式,我可以对变量进行正则表达式并立即查找所有匹配项 我不需要知道找到号码的位置,我只需要数字。
有没有办法将值复制到像这样的字符串?
Dim text As String
text = ActiveSheet.Range("C9:IQ56").Value
是不兼容的数据类型 如果我使用变体,我会获得一列列和单元格。
我加入阵列的尝试也没有成功。
text = ActiveSheet.Range("C9:IQ56").Value
textstring = ""
For i = 1 To UBound(text, 1)
textstring = textstring & " " & Join(text(i))
Next i
对此有何帮助?
答案 0 :(得分:2)
使用应用程序索引一次执行每行:
columns = [
{
heading: "Person's Name",
fieldName = "name"
},
{
heading: "Person's Age"
fieldName = "age"
} ];
people = [
{
name: "john",
age: 25,
gender: "male"
},
{
name: "mary",
age: 18,
gender: "female"
} ];
<table>
<tr>
<th *ngFor="let column of columns">{{column.heading}}</th>
</tr>
<tr *ngFor="let person of people">
<td *ngFor="let column of columns">{{person.column.fieldName}}</td>
</tr>
</table>
答案 1 :(得分:1)
您的代码中存在两个问题,即声明和变量的尺寸。您可以这样做:
Dim Text() As Variant
Text = ActiveSheet.Range("C9:IQ56").Value
textstring = ""
For i = 1 To UBound(Text, 1)
For j = 1 To UBound(Text, 2)
textstring = textstring & " " & Text(i, j)
Next j
Next i
答案 2 :(得分:1)
类似的方法,分隔符在循环后连接行字符串
添加Timer
和使用分隔符(分隔符)的功能以及行(例如“|”)和列(例如“,”)。此外,我演示了一种方法,只需为了现有技术,通过Application.Transpose()
一次在循环之后连接所有行字符串,尽管这不比@Scott Craner有效更快或更慢解决方案:+)。
<强>代码强>
Sub arr2txt()
Const SEPROWS As String = "|" ' << change to space or any other separator/delimiter
Const SEPCOLS As String = "," ' << change to space or any other separator/delimiter
Dim v
Dim textstring As String, i As Long
Dim t As Double: t = Timer ' stop watch
v = ActiveSheet.Range("C2:E2000").Value ' get data into 1-based 2-dim datafield array
For i = 1 To UBound(v, 1)
v(i, 1) = Join(Application.Index(v, i, 0), SEPCOLS)
Next i
textstring = Join(Application.Transpose(Application.Index(v, 0, 1)), SEPROWS)
Debug.Print Format(Timer - t, "0.00 seconds needed")
End Sub