Results 1 to 7 of 7

Thread: [2005] Merging Cells in Excel

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    [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


  2. #2

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    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


  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    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


  5. #5
    New Member
    Join Date
    Jul 2010
    Posts
    1

    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

  6. #6
    Lively Member
    Join Date
    Sep 2008
    Posts
    90

    Re: [2005] Merging Cells in Excel

    vb Code:
    1. Dim range1 As Excel.Range
    2.         range= xlWorkSheet.Range("A1", "A2")
    3.         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...

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
  •  



Click Here to Expand Forum to Full Width