为风数据格式化 Excel 中的组合数字
Formatting combined numbers in Excel for wind data
我在 Excel 中有一个 table 数据,其中一列是风向,另一列是风速。我想结合风速和风向,然后将其格式化为某种方式。
例如
WD
WS
COMBINED
050
12.23
50 12.23
360
21.54
360 21.54
我需要组合数据如下所示:050 12 或 360 21 等等。
我已经使用以下代码成功地将数据组合到一个新列中,但我无法终生格式化我需要的数字。非常感谢任何帮助!
Public Sub CombineWind()
Dim xy As Worksheet
Set xy = Worksheets("combine")
Dim LRow As Long
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(8).Insert
xy.Range("H3:H" & LRow).Formula = "=B3 & "" "" & C3"
End With
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(9).Insert
xy.Range("I3:I" & LRow).Formula = "=D3 & "" "" & E3"
End With
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(10).Insert
xy.Range("J3:J" & LRow).Formula = "=F3 & "" "" & G3"
End With
Range("H2") = "Average"
Range("I2") = "Min"
Range("J2") = "Max"
End Sub
下面的代码片段虽然尚未准备好粘贴和执行,但应该对您有所帮助。
Dim Arr As Variant
With ActiveSheet
' take the value of a range from A1 to end x 7 columns
Arr = .Range(.Cells(1, 1), .Cells(.Rows.Count, "A").End(xlUp)).Resize(, 7).Value
End With
With xy
For R = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(R, "H").Value = Format(Arr(3, 2), "000 ") & Format(Arr(3, 3), "hh:mm")
Next R
End With
使用ActiveSheet
总是很危险的。最好在代码中命名 sheet。
上面的代码片段将输入 sheet 读取到一个数组中。重要的是在 A1 中启动数组,以便 Arr(1, 1) = A1,因此 Arr(3, 2) = B3。无需进一步帮助即可轻松阅读。
.Cells(R, "H")
标识设置 Value
属性 的正确单元格,但 Format(Arr(3, 2), "000 ") & Format(Arr(3, 3), "hh:mm")
仅指定所采用数组的 B3 和 C3,这可能必须通过以下方式动态化仅使行号调整为 R
的某种关系。重点是展示如何设置“组合”列的值。
我在 Excel 中有一个 table 数据,其中一列是风向,另一列是风速。我想结合风速和风向,然后将其格式化为某种方式。
例如
WD | WS | COMBINED |
---|---|---|
050 | 12.23 | 50 12.23 |
360 | 21.54 | 360 21.54 |
我需要组合数据如下所示:050 12 或 360 21 等等。 我已经使用以下代码成功地将数据组合到一个新列中,但我无法终生格式化我需要的数字。非常感谢任何帮助!
Public Sub CombineWind()
Dim xy As Worksheet
Set xy = Worksheets("combine")
Dim LRow As Long
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(8).Insert
xy.Range("H3:H" & LRow).Formula = "=B3 & "" "" & C3"
End With
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(9).Insert
xy.Range("I3:I" & LRow).Formula = "=D3 & "" "" & E3"
End With
With ActiveSheet
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(10).Insert
xy.Range("J3:J" & LRow).Formula = "=F3 & "" "" & G3"
End With
Range("H2") = "Average"
Range("I2") = "Min"
Range("J2") = "Max"
End Sub
下面的代码片段虽然尚未准备好粘贴和执行,但应该对您有所帮助。
Dim Arr As Variant
With ActiveSheet
' take the value of a range from A1 to end x 7 columns
Arr = .Range(.Cells(1, 1), .Cells(.Rows.Count, "A").End(xlUp)).Resize(, 7).Value
End With
With xy
For R = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(R, "H").Value = Format(Arr(3, 2), "000 ") & Format(Arr(3, 3), "hh:mm")
Next R
End With
使用ActiveSheet
总是很危险的。最好在代码中命名 sheet。
上面的代码片段将输入 sheet 读取到一个数组中。重要的是在 A1 中启动数组,以便 Arr(1, 1) = A1,因此 Arr(3, 2) = B3。无需进一步帮助即可轻松阅读。
.Cells(R, "H")
标识设置 Value
属性 的正确单元格,但 Format(Arr(3, 2), "000 ") & Format(Arr(3, 3), "hh:mm")
仅指定所采用数组的 B3 和 C3,这可能必须通过以下方式动态化仅使行号调整为 R
的某种关系。重点是展示如何设置“组合”列的值。