Last active
August 20, 2016 09:17
-
-
Save yankchina/992b6e6274df466d47e5eb056a82be45 to your computer and use it in GitHub Desktop.
将Excel中某一列相同数值合并居中
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub 某列相同数值合并居中() | |
Application.DisplayAlerts = False | |
Dim i, j As Integer | |
Dim cel As String | |
col = Application.InputBox("请输入需要合并的列名(如A):") | |
i = 1 | |
Value = Cells(1, col) | |
For j = 2 To Cells(Rows.Count, col).End(xlUp).Row | |
If Cells(j, col) <> Value Then | |
Range(Cells(i, col), Cells(j - 1, col)).Merge | |
i = j | |
Value = Cells(i, col) | |
End If | |
Next j | |
If i <> j Then | |
Range(Cells(i, col), Cells(j - 1, col)).Merge | |
End If | |
Application.DisplayAlerts = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题
解决方法