Excel c# add cells to range
Is it pos开发者_开发技巧sible to add cells to a range? Because the cells i need, aren't next to each other.
Example:
I need to add the cells with x in one rangex 0 x x
x 0 x x x 0 x xIs this possible? and if so, how?
Thanks
Try this
VBA:
Range("B26,B19,B13").Select
C#
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B26,B19,B13", Type.Missing);
I couldn't find a way around it so I ended up having to create new series for those columns.
Excel.SeriesCollection series = chartPage[1].SeriesCollection();
Excel.Series TSeries1 = series.NewSeries();
TSeries1.XValues = xlWorkSheet.Range[xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 1]];
TSeries1.Values = xlWorkSheet.Range[xlWorkSheet.Cells[2, 5], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 5]];
TSeries1.Name = "Setpoint Value";
Excel.Series TSeries2 = series.NewSeries();
TSeries2.XValues = xlWorkSheet.Range[xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 1]];
TSeries2.Values = xlWorkSheet.Range[xlWorkSheet.Cells[2, 6], xlWorkSheet.Cells[chart1.Series[0].Points.Count + 1, 6]];
TSeries2.Name = "Process Value";
VBA
Option Explicit
Sub ShowAreaUse()
Dim oRange As Range
Dim oArea As Range
'create range with four cells
Set oRange = Range("C9,E22,F15,I6")
Debug.Print "Range with four area ranges"
Debug.Print oRange.Address
For Each oArea In oRange.Areas
Debug.Print " " + oArea.Address
Next
'add more cells
Set oRange = Range(oRange.Address + ",A1:B10")
Debug.Print "Range with added cells"
Debug.Print oRange.Address
For Each oArea In oRange.Areas
Debug.Print " " + oArea.Address
Next
Debug.Print "Dump Range Cells"
For Each oArea In oRange
Debug.Print " " + oArea.Address
Next
End Sub
ignore this, my suggestion didn't work properly
精彩评论