vba 求助 谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/04 05:08:05
如果 cells(1,1)=cells(1,2) 那么我要cells(1,1)的格式和cells(1,3)的一样 包括填充色 字体等等(所有格式一样) 用哪个函数 谢谢
copy 是连内容都copy过去了 我现在只要格式一样内容不需要一样的 怎么玩? 谢谢.
按要求做的一个命令按钮代码:

Private Sub CommandButton1_Click()
If Cells(1, 1) = Cells(1, 2) Then
Cells(1, 3).Copy
Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Else
Cells(1, 1).Font.Color = 0
Cells(1, 1).Interior.ColorIndex = 0
End If
End Sub

如果sub sheetselecctionchange 就会出现问题了 就是光标一直在cells(1,3) 其他的都不可以操作了
懂我的意思吗?
怎么解决啊 我现在就要在selectionchange事件中应用.

按要求做的一个命令按钮代码:

Private Sub CommandButton1_Click()
If Cells(1, 1) = Cells(1, 2) Then
Cells(1, 3).Copy
Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Else
Cells(1, 1).Font.Color = 0
Cells(1, 1).Interior.ColorIndex = 0
End If
End Sub

Cells(1, 1).Copy
Cells(1, 3).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

这种代码,录制个宏,就行了。复制—选择性粘贴—格式