我目前正在處理合并單元格、計數和if 陳述句。

所以問題是,對于第 14 行,如果列中有合并單元格,則輸出應為 0 或為空,但如果沒有,則應應用影像中顯示的公式。
If MERGE
Cell in Row 14 = Empty
Else
Cell in Row 14 = Formula
我正在考慮這個流程,但我不知道如何開始執行它。
uj5u.com熱心網友回復:
Cells(r, c).Select andDebug.Print ActiveSheet.Cells(r, c).MergeArea.Address` 供你除錯(F8),為你的公式,快速記錄宏,如果需要理解和適應它可以作業。
要確定單元格是否合并:
如果 Len(ActiveSheet.Cells(r, c).MergeArea.Address) > 4 那么
但是,請注意 AA1... = Len($AA$10) = 6,而不是合并,好的。
當然,還有比這一種更好的方式來閱讀電子表格。請繼續關注詳情。
任何
Sub Detect_Merge()
Dim lr1 As Long, lc1 As Integer, maxR As Long, maxC As Integer
Dim MergeColunm As Boolean
ActiveSheet.PageSetup.Orientation = xlLandscape
DisplayAlerts = True
With ActiveSheet.UsedRange
lr1 = .Rows.Count
lc1 = .Columns.Count
End With
maxR = lr1
maxC = lc1
If maxR < lr1 Then maxR = lr1
If maxC < lc1 Then maxC = lc1
For c = 1 To maxC
MergeColunm = False
For r = 1 To maxR
'Debug.Print ActiveCell.MergeArea.Columns.Count 'this not help
If Len(ActiveSheet.Cells(r, c).MergeArea.Address) > 5 Then
MergeColunm = True
ActiveSheet.Cells(r, c).Select
Debug.Print "Merge True"
Debug.Print ActiveSheet.Cells(r, c).MergeArea.Address
Else
ActiveSheet.Cells(r, c).Select
Debug.Print "Merge False"
Debug.Print ActiveSheet.Cells(r, c).MergeArea.Address
End If
If (MergeColunm = False) And (r = 14) And (c >= 2) Then
ActiveSheet.Cells(r, c).FormulaR1C1 = "=IF(R[-13]C="""","""",COUNTIF(R[-11]C:R[-1]C,"""")-COUNTBLANK(R3C1:R13C1))"
ElseIf (MergeColunm = True) And (r = 14) And (c >= 2) Then
ActiveSheet.Cells(r, c).FormulaR1C1 = "I don't do formulas - I write vba"
End If
Next r
Next c
MsgBox "Terminado - Finished"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/315576.html
