0

I am trying to move rows of text into one column in Excel that's in a new Sheet. The transpose function works well, but will only move one row at a time. I would like to get a macro that will convert thousands of rows of data across multiple columns into one column. Please see example below (I've separated each column in the row by semi-colons). Thanks in advance for any help.

Rows:

Avila P, 2005, CHEM ENG J; Barbero BP, 2008, CHEM ENG J; Crookes R, 2004, SERIES MAT SUS APLIC
Duran FG, 2009, APPL CATAL B-ENVIRON;  Amini SK, 2004, CHEM PHYS LETT
Ali MH, 2005, SYNTHESIS-STUTTGART; Arya P, 2001, CURR OPIN CHEM BIOL; Balunas MJ, 2008, J NAT PROD

Column:

Avila P, 2005, CHEM ENG J
Barbero BP, 2008, CHEM ENG J
Crookes R, 2004, SERIES MAT SUS APLIC
Duran FG, 2009, APPL CATAL B-ENVIRON
Amini SK, 2004, CHEM PHYS LETT
Ali MH, 2005, SYNTHESIS-STUTTGART
Arya P, 2001, CURR OPIN CHEM BIOL
Balunas MJ, 2008, J NAT PROD
4

4 回答 4

2

如果我正确阅读了这个问题,我认为以下代码会起作用:

Dim c as Range, Rng as Range, cDest as Range
Dim x as long
Dim shOrig as worksheet, shDest as WorkSheet

Set shOrig = Sheets("NameOfSheetWithData")
Set shDest = Sheets("NameOfSheetToPasteTo")

Set Rng = shOrig.Range("A1:Z100") ' Set to range where data is held

Set cDest = shDest.Range("A1") ' Cell to start pasting data into

x = 0

For Each c In Rng
    If c.Value <> "" Then ' Skip blank cells
        cDest.Offset(x, 0).Value = c.Value
        x = x + 1
    End If
Next c
于 2013-05-01T00:36:38.150 回答
1

Excel上有一个叫做“文本到列”的功能,可以用来解决这类问题。

选择数据,单击“Text to Columns”(在“Data”选项卡中),选择“Delimited”,单击“next”,在这种情况下选择“Semicolon”作为分隔符。

当您再次单击下一步时,对话框将显示您的结果的外观。每个集合将存储在同一行的不同列中。

默认情况下,原始数据将替换为第一列,除非您在对话框中更改目标。

单击完成以查看结果。

于 2014-08-01T07:08:09.073 回答
0

如果我理解正确,则 OP 对稍微低于“正面”的方法持开放态度,并且可以通过 Word 获得解决方案:

  1. 复制电子表格数据和主页 > 剪贴板 > 将选择性粘贴到 Word 中作为无格式文本。(这会自动用制表符替换单元格边界。)
  2. 选择,插入 > 表格 > 表格 - 将文本转换为表格,列数设置为1(分隔文本应在选项卡中预设)。
  3. 选择结果并粘贴回 Excel。
于 2013-05-02T17:05:41.023 回答
0

使用 Excel 对象模型的新功能编写宏的一种标准技术是:

  • 以微型录制宏
  • 然后使用 VBA 编辑器将宏展开为全尺寸。
于 2013-05-01T02:12:16.140 回答