+ Reply to Thread
Results 1 to 13 of 13

how to select a variable row depending on a number i introduce

  1. #1
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    how to select a variable row depending on a number i introduce

    hi!
    i want to introduce a number in the textbox1, and that number sets which entire row to select for making a chart. i thought of something like this, but i cant put the variable x just like that. please help!

    Private Sub CommandButton1_Click()
    Dim x As String

    If TextBox1.Text <> "" Then
    x = TextBox1.Text
    Range("Ax:Mx").EntireRow.Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("'sheet1'!$A$x:$M$x")
    ActiveChart.ChartType = xlLineStacked
    UserForm1.Hide
    End If

    End Sub
    Last edited by Antonio Rosales; 01-24-2013 at 11:20 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    Try this.
    Please Login or Register  to view this content.
    PS Please edit your post to use code tags.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    thanks! i just register so i didnt know about the tags, next time.

    i try doing it with 2 textbox now, but y throws me an error

    Please Login or Register  to view this content.
    Last edited by Antonio Rosales; 01-24-2013 at 11:49 AM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    Can you edit and add the tags?

    Makes it a lot easier to read the code.

    All you need to do is select the code and click the # on the toolbar.
    Last edited by Norie; 01-24-2013 at 11:49 AM.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    Thanks for adding the tags.

    The problem is the ; separating the range references here.
    Please Login or Register  to view this content.
    Replace the ; with a , and the code should work.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    it still shows me an error on the under line part, were it says "ActiveSheet.Shapes.AddChart.Select"
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    it still shows me an error on the under line part, were it says "ActiveSheet.Shapes.AddChart.Select"

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    It works fine for me on a worksheet which is blank, apart from data.

    Can you post a sample workbook?

  9. #9
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    i think i uploaded
    Attached Files Attached Files

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    I've tried the uploaded workbook and can't reproduce the error.

    What did you put in the textboxes when the code errors?

  11. #11
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    in the textbox1 i put 2 and in the textbox2 i put 4 to select that entire row and show it in a chart but i cant :S. iam i doing something wrong?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to select a variable row depending on a number i introduce

    That's exactly what I did and the code worked.

    I even tried entering rows that were blank and all it did was produce a blank chart.

    Is there anything else going on in the workbook or on the worksheet?

  13. #13
    Registered User
    Join Date
    01-24-2013
    Location
    chile
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: how to select a variable row depending on a number i introduce

    no nothing, that exact workbook doesent work, it says " errror 1004, error define by the application or the object"
    sorry for all of the problems! thank you for helping!

+ 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