Runtime error 91 and 2147417851 (80010105)

Closed
HS55 Posts 2 Registration date Tuesday 3 November 2009 Status Member Last seen 5 November 2009 - 4 Nov 2009 à 15:17
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 5 Nov 2009 à 19:40
Hello,


I get an error in the following line (at times):

rowTotal = ActiveSheet.UsedRange.Rows.count --> run-time error 91 Object variable or with block variable not set.

Also, I am creating a bar graph based on data in on of the sheets in my Excel Workbook.
When I first run the script, the graph has one bar and the x and y axis data are reversed. When I re-run it, it graphs correctly. I'm not quite sure why this is occuring.

With oChart
.ChartType = xlColumnClustered
.HasTitle = True
.SetSourceData Source:=Sheets("Sheet2").Range("B1:B148"), PlotBy:= _
xlColumns 'data source
.SeriesCollection(1).XValues = Sheets("Sheet2").Range("A1:A148") 'naming the x-axis
.ChartTitle.Characters.Text = "QTP License Usage 2009"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Date (2009)" 'x axis title
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Number of Users" 'y axis title
With .Parent 'location of Top and Left of chart
.Top = Range("F9").Top
.Left = Range("F9").Left
.Name = "Chart1"
End With
End With

-VBA to create a graph in excel.
Thanks in advance.
Related:

3 responses

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
5 Nov 2009 à 06:09
regarding first question what is dimension of rawstotal
it should be
dim rowstotal as long

not as range

check this.
HS55 Posts 2 Registration date Tuesday 3 November 2009 Status Member Last seen 5 November 2009
5 Nov 2009 à 10:40
rowTotal is an integer. I'm just trying to figure out the number of rows of data in the sheet.
I changed it to Long, but I still have the same problem. When I run it once, it works...when I run it again, it gives run-time error 91.

Same thing with the 2nd problem - I get the error, then when I stop the macro and re-run, it works.
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
5 Nov 2009 à 19:40
I wonder whether it is possible for you to post the first part of the code relevant to the first question