Các bác giúp em chuyển đổi giữ liệu ở 2 ô trong excell cho nhau với. Có chức năng nào như vậy không hay làm phải làm thủ công. Hoặc có macro nào đáp ứng được không hả các bác ơi. Giúp em với. ngoctcef@gmail.com
Lần chỉnh sửa cuối:
Dù cắt dán thì cách làm cũng sẽ giống như bạn ChanhTQ@ vừa nói mà thôi...Tại sao không dùng cắt dán hả bạn?
Các bác giúp em chuyển đổi giữ liệu ở 2 ô trong excell cho nhau với. Có chức năng nào như vậy không hay làm phải làm thủ công. Hoặc có macro nào đáp ứng được không hả các bác ơi. Giúp em với. ngoctcef@gmail.com
Bạn chép code này vào trang viết VBA của sheet mà bạn muốn chuyển đổi ô. Nó dùng 2 thao tác chuột là click đôi và click phải.Cảm ơn các bác, em muốn làm được chức năng chuyển đổi dữ liệu giữa 2 ô giống như chơi Picachu ấy, vì em xếp thời khóa biểu bao nhiêu môn mà cắt dán thì không thể khả thi được. Mỗi khi hoán vị các tiết học cho nhau mà làm cắt dán em nghĩ là hạ sách lắm. Các bác nghĩ giúp em với. Rất cảm ơn các bác
Public HVi1
Public Rng1 As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Set Rng1 = Target
HVi1 = Rng1.Value
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Rng1 = Target.Value
Target.Value = HVi1
End Sub
[COLOR=#000000][COLOR=#007700][FONT=Courier New]Public [/FONT][/COLOR][FONT=Courier New][COLOR=#0000bb]HVi1[/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]Public [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Rng1[/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]Public [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]TG[/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]Private [/COLOR][COLOR=#0000bb]Sub Worksheet_BeforeRightClick[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]ByVal Target [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Range[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Cancel [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Boolean[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]Cancel [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True[/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]If [/COLOR][COLOR=#0000bb]HVi1 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"" [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Then[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]Rng1 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Target[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Address[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]0[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]HVi1 [/COLOR][COLOR=#007700]= [/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]Target[/FONT][/COLOR] [FONT=Courier New][COLOR=#007700]Else[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]TG [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Target[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Value[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]Target[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Value [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]HVi1[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Rng1[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000bb]Value [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]TG[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb][COLOR=white]___[/COLOR]HVi1 [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#dd0000]""[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]End [/COLOR][/FONT][COLOR=#007700][FONT=Courier New]If[/FONT][/COLOR] [COLOR=#0000bb][FONT=Courier New]End Sub[/FONT][/COLOR][/COLOR]
Sử dụng một động tác nhấn chuột phải thật tiện nhưng áp dụng vào thực tế thì bất tiện.Xin góp vui với!
Bạn dùng code này thỉ cần nhấn chuột phải thôi để hoán chuyển dữ liệu, không cần thay đổi động tác!