我正在寻找VBA中的宏,它通过一个范围,并使用该范围内每个单元格的给定颜色连接所有左值(直到列A)+上限值(直到第1行)。 你认为这可能吗? 谢谢
答案 0 :(得分:0)
我测试了这个,它根据你的例子工作。试一试:)
Function concatenateLeftAndTop() As String
Dim firstColumnToTheLeft As Long
Dim firstRowToTheTop As Long
Dim functionColumn As Long
Dim functionRow As Long
Dim output As String
Dim i As Long
'Set your workbook - in this version I select the active workbook
Set myBook = ActiveWorkbook
'Set up your worksheet - In this version I select the active worksheet
Set mySheet = myBook.ActiveSheet
' Finding which column and which row the function is in
functionColumn = Application.Caller.Column
functionRow = Application.Caller.Row
'Concatenating
With mySheet
' Finding the first column to the left
firstColumnToTheLeft = .Cells(functionRow, functionColumn).End(xlToLeft).Column
firstRowToTheTop = .Cells(functionRow, functionColumn).End(xlUp).Row
'Initial Value
output = .Cells(functionRow, firstColumnToTheLeft)
'Cells to the left
For i = (firstColumnToTheLeft + 1) To (functionColumn - 1)
output = output & ";" & .Cells(functionRow, i)
Next i
'Cells Above
For i = firstRowToTheTop To (functionRow - 1)
output = output & ";" & .Cells(i, functionColumn)
Next i
End With
'Output
concatenateLeftAndTop = output
End Function