Xin chào các bạn. Mình muốn ghép dữ liệu của nhiều cell khác nhau vào 1 cell duy nhất. Mình tìm trên mạng có custom function như sau:
Nhưng nó gộp tất cả giá trị trong range vào 1 cell bao gồm cả những blank cell.
Mình muốn sửa lại để nó chỉ gộp tất cả những cell có giá trị thôi thì làm thế nào?
Mong mọi người giúp đỡ.
Mã:
[COLOR=#00007F][FONT=Courier][I]Function[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] aConcat([/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]ByVal[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] r [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]As[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] Range, [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]Optional[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] Joiner [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]As[/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]String[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] = ", ") [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]As[/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]String[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]Dim[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] arr[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier][I]arr = r.Value[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]If[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] r.Count = 1 [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]Then[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier][I]aConcat = r.Value[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]ElseIf[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] r.Rows.Count > 1 And r.Columns.Count > 1 [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]Then[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier][I]aConcat = "Range error"[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]ElseIf[/I][/FONT][/COLOR][COLOR=#333333][FONT=Courier][I] r.Columns.Count = 1 [/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]Then[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier][I]aConcat = Join(Application.Transpose(arr), Joiner)[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]Else[/I][/FONT][/COLOR]
[COLOR=#333333][FONT=Courier][I]aConcat = Join(Application.Transpose(Application.Transpose(arr)), Joiner)[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]End[/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]If[/I][/FONT][/COLOR]
[COLOR=#00007F][FONT=Courier][I]End[/I][/FONT][/COLOR][COLOR=#00007F][FONT=Courier][I]Function[/I][/FONT][/COLOR]
Nhưng nó gộp tất cả giá trị trong range vào 1 cell bao gồm cả những blank cell.
Mình muốn sửa lại để nó chỉ gộp tất cả những cell có giá trị thôi thì làm thế nào?
Mong mọi người giúp đỡ.