使用vba

时间:2018-08-10 05:45:20

标签: excel vba excel-vba excel-formula

这是我的Excel工作表:

enter image description here

我需要将数字分割成没有拉动止损的旁边的列,我是VBA的新手,请建议我如何编写代码。

enter image description here

我想这样获取数据

3 个答案:

答案 0 :(得分:0)

使用宏录制文本到列我得到了以下代码。您可以根据需要自定义。希望对您有用。

Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :=".", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
    1)), TrailingMinusNumbers:=True

答案 1 :(得分:0)

我认为您需要类似的东西。

Sub SplitStuff()
'Update 20140318
Dim Rng As Range
Dim InputRng As Range, OutRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In InputRng
    xValue = Rng.Value
    xRow = Rng.Row
    For i = 1 To VBA.Len(xValue)
        OutRng.Cells(xRow, i).Value = VBA.Mid(xValue, i, 1)
    Next
Next
Application.ScreenUpdating = True
End Sub

或使用此功能;向下填充并向右填充。

=MID($A1, COLUMNS($A$1:A$1), 1)

答案 2 :(得分:0)

Dim Rng作为范围,B作为范围     Dim x作为整数,H作为整数

Set Rng = ThisWorkbook.Sheets(2).Range("B1:B220")

x = 1
For Each c In Rng
    For y = 1 To Len(c.Value)
        Rng(c.Row, x) = Mid(c.Value, y, 1)
        x = x + 1
    Next y
    x = 2
Next c

这对我有用。 谢谢!!