Run-time error '1004' Method 'Rows' of Object_Global failed
Hey !
I am writing VBA code for finding last_row of next sheet inside a chart sheet, in chart I a using Chart_MouseUp and Chart_MouseDown function here I am explaining Chart_MouseUp inside Chart_MouseDown event I am taking I am taking chart start point x and y co-ordinate and and on Chart_MouseUp event I am taking chart end point x and y co-ordinate and after this process I am storing start point and end end point x co-ordinate inside next sheet "AQ" column for this purpose I have to know number of cell which is blanked inside AQ column for this I have to know last_Row of AQ cell and for this purpose I am using this code
Dim last_Row As Integer
last_Row = Sheets(5).Range("B" & Rows.count).End(xlUp).Row
MsgBox last_Row
Run-time error '1004'
Method 'Rows' of Object_Global failed
Whenever code like
'Sheets(5).Range("AQ4") = startX
'Sheets(5).Range("AQ5") = endX is working inside same sheet
here is Chart_MouseUp event code Please I have an Idea to handle this problem then guide me
Dim startX as Long
Dim startY as String
Dim endX as Long
Dim endY as String
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
Dim myX As Variant, myY As Double
With ActiveChart
' Pass x & y, return ElementID and Args
.GetChartElement x, y, ElementID, Arg1, Arg2
' Did we click over a point or data label?
If ElementID = xlSeries Or ElementID = xlDataLabel Then
If Arg2 > 0 Then
' Extract x value from array of x values
myX = WorksheetFunction.Index _
(.SeriesCollection(Arg1).XValues, Arg2)
' Extract y value from array of y values
myY = WorksheetFunction.Index _
(.SeriesCollection(Arg1).Values, Arg2)
endX = CDate(myX)
endY = myY
' Display message box with point information
MsgBox "X = " & startX & vbCrLf _
& "Y = " & startY & vbCrLf _
& "X = " & endX & vbCrLf _
& "Y = " & endY
'Sheets(5).Range("AQ4") = startX
'Sheets(5).Range("AQ5") = endX
Dim last_Row As Integer
'Dim sh As Worksheet
last_Row = Sheets(5).Range("B" & Rows.count).End(xlUp).Row
MsgBox last_Row
End If
End If
End With
End Sub
And Chart_MouseDown event will be like this
Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
Dim myX As Variant, myY As Double
With ActiveChart
' Pass x & y, return ElementID and Args
.GetChartElement x, y, ElementID, Arg1, Arg2
' Did we click over a point or data label?
If ElementID = xlSeries Or ElementID = xlDataLabel Then
If Arg2 > 0 Then
' Extract x value from array of x values
myX = WorksheetFunction.Index _
(.SeriesCollection(Arg1).XValues, Arg2)
' Extract y value from array of y values
myY = WorksheetFunction.Index _
(.SeriesCollection(Arg1).Values, Arg2)
startX= CDate(myX)
startY= myY
End If
End If
End With
End Sub
Note : At first Chart_MouseDown event occur then after Chart_MouseUp event will be occurred
Happy Coding !
I am writing VBA code for finding last_row of next sheet inside a chart sheet, in chart I a using Chart_MouseUp and Chart_MouseDown function here I am explaining Chart_MouseUp inside Chart_MouseDown event I am taking I am taking chart start point x and y co-ordinate and and on Chart_MouseUp event I am taking chart end point x and y co-ordinate and after this process I am storing start point and end end point x co-ordinate inside next sheet "AQ" column for this purpose I have to know number of cell which is blanked inside AQ column for this I have to know last_Row of AQ cell and for this purpose I am using this code
Dim last_Row As Integer
last_Row = Sheets(5).Range("B" & Rows.count).End(xlUp).Row
MsgBox last_Row
Run-time error '1004'
Method 'Rows' of Object_Global failed
Whenever code like
'Sheets(5).Range("AQ4") = startX
'Sheets(5).Range("AQ5") = endX is working inside same sheet
here is Chart_MouseUp event code Please I have an Idea to handle this problem then guide me
Dim startX as Long
Dim startY as String
Dim endX as Long
Dim endY as String
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
Dim myX As Variant, myY As Double
With ActiveChart
' Pass x & y, return ElementID and Args
.GetChartElement x, y, ElementID, Arg1, Arg2
' Did we click over a point or data label?
If ElementID = xlSeries Or ElementID = xlDataLabel Then
If Arg2 > 0 Then
' Extract x value from array of x values
myX = WorksheetFunction.Index _
(.SeriesCollection(Arg1).XValues, Arg2)
' Extract y value from array of y values
myY = WorksheetFunction.Index _
(.SeriesCollection(Arg1).Values, Arg2)
endX = CDate(myX)
endY = myY
' Display message box with point information
MsgBox "X = " & startX & vbCrLf _
& "Y = " & startY & vbCrLf _
& "X = " & endX & vbCrLf _
& "Y = " & endY
'Sheets(5).Range("AQ4") = startX
'Sheets(5).Range("AQ5") = endX
Dim last_Row As Integer
'Dim sh As Worksheet
last_Row = Sheets(5).Range("B" & Rows.count).End(xlUp).Row
MsgBox last_Row
End If
End If
End With
End Sub
And Chart_MouseDown event will be like this
Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
Dim myX As Variant, myY As Double
With ActiveChart
' Pass x & y, return ElementID and Args
.GetChartElement x, y, ElementID, Arg1, Arg2
' Did we click over a point or data label?
If ElementID = xlSeries Or ElementID = xlDataLabel Then
If Arg2 > 0 Then
' Extract x value from array of x values
myX = WorksheetFunction.Index _
(.SeriesCollection(Arg1).XValues, Arg2)
' Extract y value from array of y values
myY = WorksheetFunction.Index _
(.SeriesCollection(Arg1).Values, Arg2)
startX= CDate(myX)
startY= myY
End If
End If
End With
End Sub
Note : At first Chart_MouseDown event occur then after Chart_MouseUp event will be occurred
Happy Coding !
Comments
Post a Comment