filmov
tv
How to Merge Cells in Excel using a VBA Code || Excel Tutorials
Показать описание
In this tutorial, let us learn How to Merge Cells in Excel using a VBA Code
Let me show this using this sample data range.
Best Laptops to use for better speed:
Let us first write a small code to merge this cells C4 and C5.
Go to VBA editor window and type the code as
Sub vba_merge()
Range("C4:C5").Merge
End Sub
Now, go to the excel sheet and run the macro to see the cells C4 and C5 merging like this.
Got it.
Now, let us try to merge the cells based on our selection.
Go to vba editor, and instead of the range in the vba code, type as selection
Sub vba_merge()
Selection.Merge
End Sub
Come to the excel, select the range from C6 to C20 and then run the macro to merge these selected cells.
The drawback of this method, is that we can have only the data of the first cell in the merged cell.
Unlike, If you want to combine data and then merge, you have to write a different code like this.
I am mentioning the code in the description as well for your ready reference.
Sub vba_merge ()
Dim val As String
Dim rng As Range
Set rng = Selection
For Each Cell In rng
val = val & " " & Cell.Value
Next Cell
With rng
.Merge
.Value = Trim(val)
.WrapText = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
Our Recommendations
***************************************************************
If you found this video valuable, give it a like. If you know someone who needs to see it, share it. Leave a comment below with your thoughts. Add it to a playlist if you want to watch it later.
***********************************************
⚡️Tools for YouTube vlogging:
***********************************************
***********************************************
⚡️You Can Connect with Me at:
***********************************************
#dptutorials #Primavera #PrimaveraFree #Exceltraining #ExcelTricks #ExcelTips #ExcelFreeTraining #ExcelFreeLearning
⚡️Tags: -
excel formulas in English, excel in English, excel tutorial in English,ms excel in english,ms excel tutorial in English, learn excel in English,vlookup in excel in English, learn ms excel in English, excel training, excel tutorial, Microsoft Excel 2007, learn excel,tutorial excel, ms excel tutorial, excel tutorials,ms excel 2007,Microsoft Excel training,learn excel online,learning excel,free excel training,online excel training,advanced excel tutorial,excel tutorial, excel formulas and functions, excel formulas, excel tutorial in Hindi, excel formulas and functions in Hindi, excel tricks, excel in Hindi, excel shortcut keys, excel vlookup, excel formulas in Hindi, excel for beginners, excel for accounting, excel formulas and functions tutorial, Excel Sum Formula, Sum Formula series, excel attendance sheet, excel salary sheet, excel stock maintain, excel data entry, advanced excel tutorial,excel formulas,excel tutorial,vlookup excel,excel accounting,excel for beginners
⚡️Note: This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!
Let me show this using this sample data range.
Best Laptops to use for better speed:
Let us first write a small code to merge this cells C4 and C5.
Go to VBA editor window and type the code as
Sub vba_merge()
Range("C4:C5").Merge
End Sub
Now, go to the excel sheet and run the macro to see the cells C4 and C5 merging like this.
Got it.
Now, let us try to merge the cells based on our selection.
Go to vba editor, and instead of the range in the vba code, type as selection
Sub vba_merge()
Selection.Merge
End Sub
Come to the excel, select the range from C6 to C20 and then run the macro to merge these selected cells.
The drawback of this method, is that we can have only the data of the first cell in the merged cell.
Unlike, If you want to combine data and then merge, you have to write a different code like this.
I am mentioning the code in the description as well for your ready reference.
Sub vba_merge ()
Dim val As String
Dim rng As Range
Set rng = Selection
For Each Cell In rng
val = val & " " & Cell.Value
Next Cell
With rng
.Merge
.Value = Trim(val)
.WrapText = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
Our Recommendations
***************************************************************
If you found this video valuable, give it a like. If you know someone who needs to see it, share it. Leave a comment below with your thoughts. Add it to a playlist if you want to watch it later.
***********************************************
⚡️Tools for YouTube vlogging:
***********************************************
***********************************************
⚡️You Can Connect with Me at:
***********************************************
#dptutorials #Primavera #PrimaveraFree #Exceltraining #ExcelTricks #ExcelTips #ExcelFreeTraining #ExcelFreeLearning
⚡️Tags: -
excel formulas in English, excel in English, excel tutorial in English,ms excel in english,ms excel tutorial in English, learn excel in English,vlookup in excel in English, learn ms excel in English, excel training, excel tutorial, Microsoft Excel 2007, learn excel,tutorial excel, ms excel tutorial, excel tutorials,ms excel 2007,Microsoft Excel training,learn excel online,learning excel,free excel training,online excel training,advanced excel tutorial,excel tutorial, excel formulas and functions, excel formulas, excel tutorial in Hindi, excel formulas and functions in Hindi, excel tricks, excel in Hindi, excel shortcut keys, excel vlookup, excel formulas in Hindi, excel for beginners, excel for accounting, excel formulas and functions tutorial, Excel Sum Formula, Sum Formula series, excel attendance sheet, excel salary sheet, excel stock maintain, excel data entry, advanced excel tutorial,excel formulas,excel tutorial,vlookup excel,excel accounting,excel for beginners
⚡️Note: This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!
Комментарии