如何在VBA中使用绝对单元格引用合并3个单元格

时间:2022-06-15 11:51:00

Trying to put together a VBA macro Im trying to reference Sheet1A8(CSWAH_) as an absolute cell reference and merge SeparateA7(Last Name) and SeperateB7(First Name) so they'll display in SeperateE7(ASA Naming) and be able to carry it all the way down from E7 to E100. Is something like this even possible?

试图组合一个VBA宏我试图引用Sheet1A8(CSWAH_)作为绝对单元格引用并合并SeparateA7(姓氏)和SeperateB7(名字),这样它们将显示在SeperateE7(ASA命名)中并能够携带它从E7到E100一路下行。这样的事情甚至可能吗?

如何在VBA中使用绝对单元格引用合并3个单元格

1 个解决方案

#1


0  

Try this.

尝试这个。

Sub Demo()
    Dim ws As Worksheet
    Dim rng As Range
    Dim lastRow As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")      'change Sheet1 to your data sheet
    With ws
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'last row with data using Column A
        Set rng = .Range("E7:E" & lastRow)               'set range in Column E
        rng.Formula = "=$B$1&""_""&A7&"",""&B7"          'enter formula in range
        rng.Value = rng.Value                            'display values in range
    End With
End Sub

如何在VBA中使用绝对单元格引用合并3个单元格

#1


0  

Try this.

尝试这个。

Sub Demo()
    Dim ws As Worksheet
    Dim rng As Range
    Dim lastRow As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")      'change Sheet1 to your data sheet
    With ws
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'last row with data using Column A
        Set rng = .Range("E7:E" & lastRow)               'set range in Column E
        rng.Formula = "=$B$1&""_""&A7&"",""&B7"          'enter formula in range
        rng.Value = rng.Value                            'display values in range
    End With
End Sub

如何在VBA中使用绝对单元格引用合并3个单元格