这是我的第一篇帖子......
我正在尝试创建一个宏来执行以下操作:
答案 0 :(得分:5)
避免循环遍历所有细胞是件好事。如果数据集增长,宏可能变得太慢。使用特殊单元格和粘贴乘以1的特殊操作是完成任务的有效方法。
这有效......
drawSineGraph(state, direction) {
d3.select('.sine-curve').remove();
const increase = 54 / 1000;
state.sineIncrease = state.sineIncrease || 0;
state.sineIncrease += increase;
const sineData = d3.range(0, state.sineIncrease)
.map(x => x * 10 / 85)
.map((x) => {
return {x: x, y: Math.sin(x)};
});
state.nextCoord = {x: state.xScale(_.last(sineData).x), y: state.yScale(Math.sin(_.last(sineData).y) + 1)};
const sine = d3.svg.line()
.interpolate('monotone')
.x( (d) => {return state.xScale(d.x);})
.y( (d) => {return state.yScale(d.y + 1);});
state.xAxisGroup.append('path')
.datum(sineData)
.attr('class', 'sine-curve')
.attr('d', sine);
}
答案 1 :(得分:2)
试一试。只需将要查找的所有列标题名称添加到集合中即可。我假设您没有超过200列,如果您只是将for i = 1到200的部分更新为更大的数字。
Public Sub FindAndConvert()
Dim i As Integer
Dim lastRow As Long
Dim myRng As Range
Dim mycell As Range
Dim MyColl As Collection
Dim myIterator As Variant
Set MyColl = New Collection
MyColl.Add "Some Value"
MyColl.Add "Another Value"
lastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For i = 1 To 200
For Each myIterator In MyColl
If Cells(1, i) = myIterator Then
Set myRng = Range(Cells(2, i), Cells(lastRow, i))
For Each mycell In myRng
mycell.Value = Val(mycell.Value)
Next
End If
Next
Next
End Sub
答案 2 :(得分:2)
我偶然发现了这一点,对我来说,答案非常简单,无论如何如果你正在处理一个 ListObject ,那么这就是要走的路:
YOURLISTOBJECT.HeaderRowRange.Cells.Find("A_VALUE").Column
答案 3 :(得分:0)
好的,这是实现目标的简要方法。首先,找到包含Employee ID的列。然后只需将整个列设置为数字而不是文本?
With Worksheets(1) ' Change this sheet to the one you are using if not the first sheet
Set c = .Find("Employee ID", LookIn:=xlValues)
If Not c Is Nothing Then
' The column we want is c's Column.
Columns(c.Column).NumberFormat = 0
End If
End With
答案 4 :(得分:0)
为您想要的范围添加暗淡:
Dim MyRng, RngStart, RngEnd as Range
然后改变:
ActiveSheet.Range(c.Address).Offset(1, 0).Select
到下面,以便找到该列中的所有数据。
set RngStart = ActiveSheet.Cells(1, c.column)
set RngEnd = ActiveSheet.Cells(rows.count, c.column).end(xlup)
set MyRng = ActiveSheet.Range(RngStart & ":" & RngEnd)
现在你可以玩数据了。如果要将其粘贴到格式为数字的位置:
MyRng.copy
Sheets("Wherever").Range("Wherever").pastespecial xlvalues
如果你想改变你现在找到的单元格格式(How to format column to number format in Excel sheet?)是整数格式,如果你想要小数点,那么使用" number"而不是" 0":
MyRng.NumberFormat = "0"
或新目的地:
Sheets("Wherever").Range("Wherever").NumberFormat = "0"
与转换为数字功能完全匹配的常规格式:
MyRng.NumberFormat = "General"
MyRng.Value = MyRng.Value