如何将第一列的字符串值附加到行的其余部分中的所有单元格值

发布于 2025-02-01 19:28:45 字数 437 浏览 2 评论 0原文

在Excel VBA中,

我在每行的第一列中具有一个字符串值。在该行上的每一列都包含一个单词字符串。我需要将第一列附加到该行中的每个其他单元格。行是独一无二的。

”这是我想要结果的

In Excel VBA

I have a string value in the first column of each row. Each column after on that row contains a single word string. I need to append the first column to each of the other cells in that row. Rows are unique.

Example of Source Data

This is what I want the results to be

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2025-02-08 19:28:45

使用其他工作表。假设yout源数据位于名为sheet1的工作表中,只需转到另一个工作表,然后在列中贴上这些字符串值。在单元格B2类型中:

=Sheet1!B1&" <"&$A1&">"

注意公式中的混合引用。拖到右和底部,然后看到魔术:

”在此处输入图像描述

您需要拖动直到Sheet1的最后一个单元格,因此,如果您的原始数据直到单元格为止,请说> > H203,在第二张纸中,您将直接拖动直至首先直至第203行。VBA

代码相同:

Dim LR As Long
Dim WkSource As Worksheet
Dim WkDestiny As Worksheet

Set WkSource = ThisWorkbook.Worksheets("Sheet1")
Set WkDestiny = ThisWorkbook.Worksheets("Sheet2")

With WkSource
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    WkDestiny.Range("A1:A" & LR).Value = .Range("A1:A" & LR).Value 'copy first column
End With

With WkDestiny.Range("B1:F" & LR)
    .Formula = "=Sheet1!B1&" & """" & " <" & """" & "&$A1&" & """" & ">" & """"
    .Value = .Value 'paste as values
End With

“

Use a different worksheet. Let's say yout source data is in a worksheet named Sheet1 Just go to another worksheet and in column A paste those string values. In cell B2 type:

=Sheet1!B1&" <"&$A1&">"

Notice the mixed references in the formula. Drag to right and bottom and see the magic:

enter image description here

You need to drag until last cell of data from Sheet1 so if your original data goes until cell, let's say H203, in the second sheet you would drag directly until column H first and then until row 203.

VBA code would be the same:

Dim LR As Long
Dim WkSource As Worksheet
Dim WkDestiny As Worksheet

Set WkSource = ThisWorkbook.Worksheets("Sheet1")
Set WkDestiny = ThisWorkbook.Worksheets("Sheet2")

With WkSource
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    WkDestiny.Range("A1:A" & LR).Value = .Range("A1:A" & LR).Value 'copy first column
End With

With WkDestiny.Range("B1:F" & LR)
    .Formula = "=Sheet1!B1&" & """" & " <" & """" & "&$A1&" & """" & ">" & """"
    .Value = .Value 'paste as values
End With

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文