Merge cells in Excel

How to merge cells using Cell

, not Range

in vb.net

I will try this code but it doesn't work

excelSheet.Cells(1, 10).Merge()

      

Can someone help me ..

+2


a source to share


4 answers


A sheet cell property refers to a single cell. So you are trying to concatenate only the cell on A10. As its already one cell, it does nothing. I'm not sure if you can only do this with the Cells property as it will always only be one cell. Why are you avoiding Range?

This uses a range but will still use the cells property to set range constraints

excelSheet.Range(excelSheet.Cells(1, 1),excelSheet.Cells(1, 10)).Merge

      



Also, I think the command is Merge and not Merge (), at least when I run it.

Sorry if that doesn't help, give us more details and I'll look heavier if it doesn't work for you.

+18


a source


Another solution is to correct your values



ActiveCell.Value = Range("G8") & Range("H8")

      

0


a source


Try it. It can only be used for a range. I don't know how to merge cells.

Dim xlsApp As New Excel.Application
xlsApp .Visible = True
Dim xlsWorkbook As Excel.Workbook = xlsApp.Workbooks.Open("..\TestWorkbook.xls")
Dim xlsWorkSheet As Excel.Worksheet = DirectCast(xlsWorkbook.Worksheets("Sheet1"), Excel.Worksheet)
xlsWorkSheet.Range("A1:D1").MergeCells = True

      

Don't forget to import the required libraries.

0


a source


The easiest way

ExcelSheet.Range. ("A1: H1") merge ()

0


a source







All Articles