+ Reply to Thread
Results 1 to 3 of 3

Run-time error '1004'

Hybrid View

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    texas, usa
    MS-Off Ver
    Excel 2003
    Posts
    2

    Run-time error '1004'

    Hello All,

    I am trying to modify Peltier's excel vba graphing code to fit my needs. However, I keep getting a run-time error '1004' on ".Values = rngChtXVal1.Offset(irow - 1, 0)"

    Can anyone tell me what I've missed?

    Sub Multi_Range_Chart()
        Dim Cored_Wells As Integer
        Dim Current_Well As Integer
        Dim myChtObj As ChartObject
        Dim rngChtData1 As Range
        Dim rngChtData2 As Range
        Dim rngChtData3 As Range
        Dim rngChtData4 As Range
        Dim rngChtData5 As Range
        Dim rngChtData6 As Range
        Dim rngChtXVal1 As Range
        Dim irow As Long
        
            
        Current_Well = 1
            
        Cored_Wells = Application.InputBox(Prompt:="How many cored wells?", Title:="Multi Well Graphing Untility", Default:=1, Type:=1)
        If Cored_Wells = 0 Or Cored_Wells < 0 Then
            Exit Sub
        End If
            
        Do Until Current_Well = Cored_Wells + 1
            Set rngChtData1 = Nothing
            On Error Resume Next
            Set rngChtData1 = Application.InputBox(Prompt:="Select range of cored well #" & Current_Well, Title:="Multi Well Graphing Utility", Type:=8)
            On Error GoTo 0
            If rngChtData1 Is Nothing Then Exit Sub
                                    
            ' add the chart
            Set myChtObj = ActiveSheet.ChartObjects.Add _
                (Left:=250, Width:=375, Top:=75, Height:=225)
            With myChtObj.Chart
            ' make an XY chart
            .ChartType = xlXYScatterLines
            ' remove extra serious
            Do Until .SeriesCollection.Count = 0
                    .SeriesCollection(1).Delete
                Loop
            End With
            
            Select Case Current_Well
            
                Case 1
            
                    ' define chart's X values
                    With rngChtData1
                        Set rngChtXVal1 = .Rows(1).Offset(0, 1).Resize(.Columns.Count - 1)
                    End With
                    With myChtObj.Chart
                        ' add series from selected range, column by column
                        For irow = 2 To rngChtData1.Rows.Count
                            With .SeriesCollection.NewSeries
                                .Values = rngChtXVal1.Offset(irow - 1, 0)
                                .XValues = rngChtXVal1
                                .Name = rngChtData1(irow, 0)
                            End With
                        Next
                    End With
                Case 2
                    Exit Sub
                
                End Select
        Current_Well = Current_Well + 1
        Loop
    
    End Sub
    Last edited by mavrck48; 03-24-2013 at 02:28 AM. Reason: Solved

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run-time error '1004'

    When the error occurs and you DEBUG, type this in the Immediate Window (Ctrl-G) and see what the current value is:
    ? rngChtXVal1.Address
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    texas, usa
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Run-time error '1004'

    Thank you JBeaucaire. That is exactly what I needed so I could properly debug my code. I found out that I was missing the comma in the .Resize property a few lines up which was eventually causing the error. Thanks for the response, so here is some rep!
    Last edited by mavrck48; 03-24-2013 at 02:32 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1