English 中文(简体)
以列中标准为标准将单元格的内嵌单元格范围相交
原标题:Concatenate range of cells with criteria in a column

我需要帮助 瓦巴共产细胞。

I have a spread sheet: column A contain values like Product A for a few rows, Product B for a few rows, and so on. I want to concatenate, say cells in columns B-J for Product A, write the value to column K or another sheet, then do the same thing with Product B, and so on till the end of the spreadsheet.

我认为这需要一些VBA编码,我正在学习这些编码,但还没有做好这项工作。请帮助!

Thank you, cj

问题回答

我觉得这需要些瓦巴编码

不,你不需要Vba来做这个:)

将此公式放在 K1 中拖放

=B1&" "&C1&" "&D1&" "&E1&" "&F1&" "&G1&" "&H1&" "&I1&" "&J1

这将将数据与 SPACE 合并为分隔符。 如果您不想要空间, 则将上述公式修改为

=B1&C1&D1&E1&F1&G1&H1&I1&J1

如果您想要将 COMMA COMMA 连接为分隔符, 使用此

=B1&", "&C1&", "&D1&", "&E1&", "&F1&", "&G1&", "&H1&", "&I1&", "&J1

等... 等... 等一等... 等一等...

我读了它,因为你想要所有的东西 在一个单列的列中进入另一个单元格。 这是一个例行程序, 它将从您指定的单元格中收集所有数据, 并连接所有的东西, 直到数据中断 。

Option Explicit

Function ColConc(CellRef As Range, Delimiter As String)

Dim LoopVar As Long
Dim StartRow As Long
Dim EndRow As Long
Dim Concat As String
Dim Col As Long

Col = CellRef.column
StartRow = CellRef.Row
EndRow = CellRef.End(xlDown).Row

Concat = ""

For LoopVar = StartRow To EndRow
    Concat = Concat & Cells(LoopVar, Col).Value
    If LoopVar <> EndRow Then Concat = Concat & Delimiter
Next LoopVar

ColConc = Concat
End Function

call by using the formula =ColConc(A2," ") and this will get everything from cell A2, down to the end of that column, with a space as the delimiter.
The delimiter can be any string, so you can place anything between the data. A blank cell ends the data it uses for concatenating into a single string.
It will only work on the current sheet - more coding would be needed to get that part working





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签