|
3学分
本帖最后由 Quincy_xiao 于 2022-8-9 10:32 编辑
麻烦各位老师看看,附件中的三个地方需要怎么样实现,自己写过,选中合并的单元格时会出现问题。
本帖最后由 我行我速2008 于 2022-8-9 11:47 编辑
认为行就选为最佳答案
Dim R%, I%, Str$, K%
Sub 依次获取D列合并单元格的值()
With Sheets("project")
For R = 4 To .Cells(Rows.Count, 4).End(xlUp).Row
If .Cells(R, 4).MergeCells Then
I = .Cells(R, 4).MergeArea.Count
MsgBox .Cells(R, 4).Text
R = R + I - 1
End If
Next R
End With
End Sub
Sub 根据F列合并单元格获取I列对应数据()
With Sheets("project")
For R = 4 To .Cells(Rows.Count, 6).End(xlUp).Row
If .Cells(R, 6).MergeCells Then
I = .Cells(R, 6).MergeArea.Count
For K = R To R + I - 1
If .Cells(K, 9) <> "" Then Str = Str & .Cells(K, 9) & ","
Next K
If Len(Str) > 0 Then
MsgBox .Cells(R, 6).Resize(I, 6).Address & "的I列对应数据是:" & Str
Else
MsgBox .Cells(R, 6).Resize(I, 6).Address & "的I列对应数据为空"
End If
Str = ""
R = R + I - 1
End If
Next R
End With
End Sub
Sub 选中D列所有合并单元格()
Dim R%, I%, Str$
With Sheets("project")
For R = 4 To .Cells(Rows.Count, 4).End(xlUp).Row
If .Cells(R, 4).MergeCells Then
I = .Cells(R, 4).MergeArea.Count
Str = Str & .Cells(R, 4).Address(0, 0) & ","
R = R + I - 1
End If
Next R
.Range(Left(Str, Len(Str) - 1)).Select
End With
MsgBox Selection.Address
End Sub
|
最佳答案
查看完整内容
认为行就选为最佳答案
Dim R%, I%, Str$, K%
Sub 依次获取D列合并单元格的值()
With Sheets("project")
For R = 4 To .Cells(Rows.Count, 4).End(xlUp).Row
If .Cells(R, 4).MergeCells Then
I = .Cells(R, 4).MergeArea.Count
MsgBox .Cells(R, 4).Text
R = R + I - 1
End If
Next R
End With
End Sub
Sub 根据F ...
|