想要在excel中分割数据

时间:2016-09-09 17:27:27

标签: excel excel-vba vba

我有一张包含大量数据的表格。数据从html文件中复制,因此当我粘贴时它会在一个单元格中。数据如下所示:

Cell A
---------------- 
row 1 ) Text: name of my text 
----------------
row 2 ) Link: link of my text
----------------
row 3) num: 34
----------------
row 4) Some text 
----------------
data Repeat 33858 row's. 

转换此数据的任何公式或方式,或者像此一样重新排列此数据

       Cell A          |  Cell B         |  Cell C  |  Cell D   
-------------------------------------------------------- 
Row 1) Text            |  Link           |   num    |  Some text    
__________________________________________________________
Row 2) Name of my text | Link of my text | 34       | Some text
________________________________________________________
Row 3) Name of my text2 | Link of my text2 | 35       | Some text2

等等。我希望你理解我的问题并尽力帮助我。

2 个答案:

答案 0 :(得分:0)

我想你是想说你想要从导入Excel的网站上获得一段文字。

请转到数据标签>在获取外部数据>点击网络上的 >插入你的链接。

我希望我能将这些词语很好地翻译成英语,因为在其他语言中,并不是一切都是相同的。

答案 1 :(得分:0)

Sub Main()

    ' decleration
    Dim rowSource As Integer, rowDest As Integer
        rowSource = 1
        rowDest = 2

    ' titles in destination sheet
    With Application.Sheets("Sheet2")
        .Range("A1").Value = "Text"
        .Range("B1").Value = "Text"
        .Range("C1").Value = "num"
        .Range("D1").Value = "Some text"
    End With

    ' loop through all rows in source sheet
    Do While Range("A" & rowSource).Value <> ""

        ' copy data to destination in sheet2
        With Application.Sheets("Sheet2")
            .Range("A" & rowDest).Value = Range("A" & rowSource + 0).Value
            .Range("B" & rowDest).Value = Range("A" & rowSource + 1).Value
            .Range("C" & rowDest).Value = Range("A" & rowSource + 2).Value
            .Range("D" & rowDest).Value = Range("A" & rowSource + 3).Value
        End With

        ' next group
        rowDest = rowDest + 1
        rowSource = rowSource + 4

    Loop

End Sub

您需要:

  • 创建&#34; Sheet2&#34;
  • 在&#34; Sheet1&#34;中,您的33858数据进入A列。