- Tham gia
- 30/5/06
- Bài viết
- 1,798
- Được thích
- 4,707
- Giới tính
- Nam
VTD XD đã viết:Chào anh
Anh có thể giúp tôi viết đoạn code tạo phím tắt trong excel được không àh
ví dụ: Ctrl + Shift + M là Merge and Center
Ctrl + Shift + F là fill color
Trả lời:
Bạn nên dùng Macro để ghi lại, rồi sau đó gán phím nóng
Ví dụ tôi đã ghi macro, và nội dung macro như sau:
		Mã:
		
	
	Sub Macro1()
'
' Macro1 Macro
    Range("C6:D6").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
   ' [COLOR="Red"]Đoạn code ở trên là Merge cell[/COLOR]
   ' [COLOR="Red"]Đoạn code sau là tô màu với mã màu là 65535[/COLOR]
    Range("C8").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("C10").Select
End SubTừ đây bạn có thể chỉnh sửa lại như sau:
1. Code để Merge Cell
		Mã:
		
	
	Sub MergeCells()
On Error Resume Next
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .MergeCells = True
    End With
End Sub
		Mã:
		
	
	Sub FillColors()
On Error Resume Next
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
End SubChúc bạn thành công.
Lê Văn Duyệt
 
	 
	  
 
 
		 
 
		
 
 
		 
 
		
 
 
		
 
 
		 
 
		

 
 
		
 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		