Merge Cell in Excel
H开发者_JAVA百科ow to merge cells using Cell
and not Range
in vb.net
I'll try this code but it doesn't work
excelSheet.Cells(1, 10).Merge()
Can anyone help me..
The cells property of a worksheet refers to a single cell. So you are trying to merge just the cell at A10. As its already one cell, this doesn't do anything. I'm not sure you can do it with just the Cells property, as it will always be one cell only. Why are you avoiding Range?
This uses range, but would still use the cells property to target the range constraints
excelSheet.Range(excelSheet.Cells(1, 1),excelSheet.Cells(1, 10)).Merge
Also, I think the command is Merge, not Merge(), at least when I run it.
Sorry if that isn't helpful, give us some more details and I'll look harder if that doesn't work for you.
Another solution - fix to your values
ActiveCell.Value = Range("G8") & Range("H8")
Try this. It can be used for Range only. 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
Remember to import the needed libs.
easiest way
ExcelSheet.Range("A1:H1").merge()
精彩评论