From: Timothy Barnes Date: 2011-08-09T00:38:51+09:00 Subject: Re: Excel chart question --0015173ff9aa45078304aa003e41 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Aug 8, 2011 at 7:40 AM, CC Chen wrote: > On Win32ole the excel chart created > > I have two columns such as below: > > excel.Range("A1").Value = 1 > excel.Range("A2").Value = 2 > excel.Range("A3").Value = 3 > > excel.Range("B1").Value = 15 > excel.Range("B2").Value = 16 > excel.Range("B3").Value = 17 > > excel.Range("A1:A3").Select(); > excel.Range("B1:B3").Select(); > excelchart1 = workbook.Charts.Add(); > > excel.Range("B1:B3").Select(); > excelchart2 = workbook.Charts.Add(); > > It will show the error message. > Seems can't use the Select on the same worksheet. > > How to create two charts for column A and column B at the same time? > > Thanks, > > -- > Posted via http://www.ruby-forum.com/. > The problem is that once you create the first chart the range.select method is focused on the "chart sheet" and not the original sheet (with the data). Therefore you either need to set both ranges first: excel.Range("A1:A3").select excel.Range("B1:B3").select excelchart1 = workbook.Charts.add() excelchart2 = workbook.Charts.add() or you need to set the focus back on the original worksheet: excel.Range("A1:A3").select worksheet = workbook.Worksheets('Sheet1').select excelchart1 = workbook.Charts.add() excel.Range("B1:B3").select excelchart2 = workbook.Charts.add() My preference would be the first plus associating the ranges with variables and not using select: range_1 = excel.range("A1:A3") range_2 = excel.range("B1:B3") excelchart1 = workbook.charts.add(range_1) excelchart2 = workbook.charts.add(range_2) Timothy --0015173ff9aa45078304aa003e41--