Runtime error 91 and 2147417851 (80010105)

Closed
HS55 Posts 2 Registration date Tuesday November 3, 2009 Status Member Last seen November 5, 2009 - Nov 4, 2009 at 03:17 PM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Nov 5, 2009 at 07:40 PM
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 June 14, 2009 Status Contributor Last seen August 7, 2021 811
Nov 5, 2009 at 06:09 AM
regarding first question what is dimension of rawstotal
it should be
dim rowstotal as long

not as range

check this.
0
HS55 Posts 2 Registration date Tuesday November 3, 2009 Status Member Last seen November 5, 2009
Nov 5, 2009 at 10:40 AM
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.
0
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Nov 5, 2009 at 07:40 PM
I wonder whether it is possible for you to post the first part of the code relevant to the first question
0