+ Reply to Thread
Results 1 to 12 of 12

macro to delete specific rows

  1. #1
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    macro to delete specific rows

    hello !
    first time here.

    i'm having trouble with one xls. It contains data which i want to put in mysql database through csv but first i need to remove all the unnecessary rows. The spreadsheet is divided into pages which all contain exactly the same amount of rows from either side of the table (which contains the data i need).

    I wonder if a simple macro would be of use in my case. For example, one which when i click on the last row of table knows to delete n rows (until the beginning of another table) and then skips the table (n rows) and finally loops this action n times or until the end of spreadsheet.

    Any help would be greatly appreciated! You would save me hours and hours of work doing this by hand.

  2. #2
    Registered User
    Join Date
    01-31-2013
    Location
    Derby, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: macro to delete specific rows

    Could you attach an example of the spreadsheet please? I believe that building a filter into the macro may be the best way to get the desired result.

    Regards

    Rob

  3. #3
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    here it is. as an example i've filled the rows i don't want in red for the first couple of pages. also i have these rows which are empty in the table (13,14 ...). any idea how to get rid of them?

    Tablica(1).xls
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    1st hyperlink is better. disregard second

  5. #5
    Registered User
    Join Date
    08-28-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: macro to delete specific rows

    Will this always be the format of your worksheet?
    The PREDMET column is having only 12 values always, would this change according to the sheet?

  6. #6
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    aksappy, the number of values of PREDMET change. predmet is translated as subject or class. values of 2nd column (OCJENA) are grades. number of subjects vary across school for different vocations.

    but the macro doesn't need to be that universal. i can adapt it according to the number of subjects if necessary. this solution also reduces the workload significantly!
    Last edited by drips; 02-01-2013 at 11:43 AM.

  7. #7
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    :::bump:::

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to delete specific rows

    Drips,
    I do not think bumping would react for memers to reply, instead you should explain your request. You have highlighted the cells you want to delete, but what is the criteria,or condition for deleting a partcular cell? On what base?

  9. #9
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    condition is a relative position. it needs to say that from currently selected row delete x number of rows then jump another number of rows and do the same until the end. that's all. i can't imagine this being so hard for experienced macro developers to answer. i tried recording this but when i ran the macro it didn't jump the rows i don't want to delete.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to delete specific rows

    relative position? Which position? All I see is the red colour cells. For e.g you have GOSPODARSKA ŠKOLA in row 1 and few more lines below. Do you want to delete all cells which have GOSPODARSKA ŠKOLA, or more?

  11. #11
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    i want to delete ALL CELLS in red (and those which are not in red but fit the pattern of red ones which serve as an example. by pattern i mean the rowspan). whether they're empty or not doesn't matter. think of it as a block of cells. first block is misleading - sorry for that. 2nd block of red cells contains exactly 26 rows and all subsequent blocks also. so i guess, the condition is n(rowspan) == 26. the tables which i do not want deleted(cells in white) never contain 26 rows.
    i guess, but do not know because i've never written any macros, you cannot define blocks of cells with merely the number of rows - that's why i thought that macro could have a sequence which (1) selects 26 rows from starting position(relative not absolute) and (2)deletes them, then (3)ommits around 20 rows (this varies) and loops - so again (1)selects and deletes 26 rows and so on...

  12. #12
    Registered User
    Join Date
    02-01-2013
    Location
    Zagreb
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: macro to delete specific rows

    so this is the solution:
    Please Login or Register  to view this content.
    i wrote it myself. (1st loop is needed 'cause of inconsistencies in the pattern)
    i guess i'm kind of surprised that no one helped me on this real simple problem but hey i learned some VBA skills :D
    anyway, thanks for taking an interest!

+ 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