|
-
Nov 30th, 2007, 04:10 AM
#1
Thread Starter
Fanatic Member
[2005] Merging Cells in Excel
I want to insert a value in the cell of excel, I did it, Now i have to merge the next cell too..
For example, i have inserted "Sample" in the the cell (2,B+C)
2 -> Row.
B+C -> Columns to be merged.
In this way i inserted the value,
Code:
WorkSheets.Cells(2,B).value="Sample"
Next how to merge it,????
Visual Studio.net 2010
If this post is useful, rate it

-
Nov 30th, 2007, 04:22 AM
#2
Thread Starter
Fanatic Member
Re: [2005] Merging Cells in Excel
Code:
Worksheets.Range("A1","B1").Merge()
this works great for merging the cells,But three cells(A1,B1,C1) merging and
when we do merge manually,the value inside the cell alligned "Center" automatically, When i try through coding its not happening,the value is in left left, i.e the value in the "A1" alone
What i want to do for this??
Last edited by vijy; Nov 30th, 2007 at 05:57 AM.
Visual Studio.net 2010
If this post is useful, rate it

-
Dec 3rd, 2007, 02:37 AM
#3
Re: [2005] Merging Cells in Excel
Thread Moved
Thats because it does two tasks at once, hence "Merge & Center".
Code:
Public Sub MegerCenter()
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 4th, 2007, 12:25 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Merging Cells in Excel
Thanks Rob, i solved it on that day itself from ur signature
Last edited by vijy; Dec 4th, 2007 at 12:34 AM.
Visual Studio.net 2010
If this post is useful, rate it

-
Jul 21st, 2010, 06:28 PM
#5
New Member
Re: [2005] Merging Cells in Excel
try this
Code:
objRango = objHojaExcel.Range("A7:D7")
objRango.Merge()
objRango.HorizontalAlignment = Excel.Constants.xlCenter
objRango.WrapText = True
objRango.ShrinkToFit = True
-
Feb 2nd, 2011, 09:06 PM
#6
Lively Member
Re: [2005] Merging Cells in Excel
vb Code:
Dim range1 As Excel.Range range= xlWorkSheet.Range("A1", "A2") range.Merge()
it doenst merge the cells.. how can i fix this
PL:VB2008 
LEVEL: beginner
There must be a simpler way to do this...
-
Feb 3rd, 2011, 12:05 AM
#7
Re: [2005] Merging Cells in Excel
I don't remember the exact syntax but try any one of the below.
1)
Dim range1 As Excel.Range
Range = xlWorksheet.Range("A1:A2")
Range.Merge()
2) xlWorksheet.Range("A1", "A2").Merge
3)
Dim range1 As Excel.Range
Range = xlWorksheet.Range("A1", "A2")
Range.Merge (True)
Sid
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|