我有一个宏,它采用一列并基本上复制每一行:
"filter": {
"bool": {
"must": [
{
"range": {
"utctimestamp": {
"from": 1460407864660,
"to": 1460409664660
}
}
},
{
"fquery": {
"query": {
"query_string": {
"query": "_type:(\"foo\")"
}
},
"_cache": true
}
}
]
输入
101
102
103
104
105
输出
101
101
102
102
103
103
104
104
105
105
但是,我无法添加新数据,只能复制新数据,因为宏适用于整个工作表。
我需要添加什么才能让我只针对选定的单元格运行宏?
答案 0 :(得分:1)
仅执行选定的单元格:
Sub Duper()
Dim i As Long
For i = (Selection.Row + Selection.Rows.Count - 1) To Selection.Row Step -1
Rows(i).Copy
Range(Rows(i + 1), Rows(i + 1)).Insert Shift:=xlDown
Application.CutCopyMode = False
Next i
End Sub
因此,选择所需的单元格,然后运行它。
答案 1 :(得分:0)
建议你使用数组而不是循环(速度):
Sub EddieBetts()
Dim rng1 As Range
Dim X, Y
Dim lngCnt As Long
Set rng1 = Selection
X = Application.Transpose(Selection)
ReDim Y(1 To UBound(X) * 2)
For lngCnt = 1 To UBound(X)
Y(2 * lngCnt - 1) = X(lngCnt)
Y(2 * lngCnt) = X(lngCnt)
Next
rng1.Offset(rng1.Rows.Count).Rows.Insert xlDown
rng1.Resize(rng1.Rows.Count * 2).Value2 = Application.Transpose(Y)
End Sub