+ Reply to Thread
Results 1 to 8 of 8

looping through a range

  1. #1
    Registered User
    Join Date
    05-08-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    36

    Question looping through a range

    Hi guys,

    I'm quite new to Excel programming so I was wondering if someone could help me with this :

    I developed this macros to open a txt file into xls, however, im only interested in some part of the data in those files, so id like to delete the rest in a simpler way than this:

    [COLOR="#FF0000"]
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    The blue part is the part id like to replace

    you'll notice there is a relation between every set I want to delete
    701+700 = 1401, 1401+700=2101 ......etc (top to bottom)
    701+1448= 2149, 1401+1448=2849 ......etc (sideways, set of rows)

    Any help would be much appreciated

    Cheers,

    Sol
    Last edited by arlu1201; 05-08-2012 at 11:58 AM. Reason: Code tags added. Pease do so in future.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: looping through a range

    You do not need to use select statements. You are having overlapping ranges. For e.g Some rows from the 1st set (701 to 2149) will already be present in the 2nd set (1401 to 2849).
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    05-08-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: looping through a range

    Thanks for the reply arlu

    What youre saying is true but thats before the lines get deleted as the code moves on those overlaps wont exist anymore.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: looping through a range

    What i mean is, instead of having so many lines of code, you can have just 1 line
    Please Login or Register  to view this content.
    (change the right hand side number to whatever is your last row).

  5. #5
    Registered User
    Join Date
    05-08-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: looping through a range

    Yeah I understand, but there are some lines in the middle which i still want, for instance if I want lines2,3 and 5,6 in the following few lines then i need to delete 1, 4 and 7 noting that each of those lines represents a set of rows. When line1 is deleted line 4 becomes number 3 and thats why it seems like theres and overlap.

    Line1
    Line2
    Line3
    Line4
    Line5
    Line6
    Line 7

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: looping through a range

    In that case, try this
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-08-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: looping through a range

    It looks like it should work, I'll try it and get back to you.

  8. #8
    Registered User
    Join Date
    05-08-2012
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: looping through a range

    Tried it works great !!
    Thanks so much mate you've saved me so much time as I've got loads of those files with different steps counts.


    Quote Originally Posted by arlu1201 View Post
    In that case, try this
    Please Login or Register  to view this content.

+ 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