[英]Excel VBA Get values of merged cells
我發現了類似的問題,但並沒有幫助我。 我有一列合並和非合並的單元格。 我想得到他們的價值觀。 我不知道如何使用它:
Set ma = myWorkbook.Range("C2").MergeArea
sValue = ma.Cells(c.Row, 1).Value
看我的代碼:
Private Function GetValueOfMergedCells(sName, iColumn)
Set myWorkbook = Workbooks().Worksheets()
Set c = myWorkbook.Cells.Find(What:=sName, After:=ActiveCell, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not c Is Nothing Then
If (iColumn <> 2) Then
'...
Else
Set ma = NEWDevicesWS.Range("C2").MergeArea
MsgBox ma.Cells(c.Row, 1).Value
GetValueOfMergedCells = ma.Cells(c.Row, 1).Value
End If
Else
'...
End If
End Function
Sub main()
Set firstWorkbook = Workbooks().Worksheets()
' Get array of strings
Dim aNames() As String
aNames = ImportSamplesNames()
For i = 1 To UBound(aNames())
firstWorkbook.Cells(3 + i, 2) = GetValueOfMergedCells(aNames(i), 2)
Next i
End Sub
我做錯了什么?
無法追蹤您的代碼
因此希望:
ma.Resize(1, 1).Value
會做
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.