+ Reply to Thread
Results 1 to 4 of 4

Deleting Rows using VBA macro

  1. #1
    Registered User
    Join Date
    02-25-2013
    Location
    L.A
    MS-Off Ver
    Excel 2010
    Posts
    19

    Deleting Rows using VBA macro

    Hi everyone,

    Please refer to the attached workbook.

    So there are 3 columns, column A is dates, column B is values related to a bank and column C is "exitflag". Essentially what I want to do is the following:

    If the number is 1 under "exitflag", then I want to delete the entire row, eg, in row 2, "exitflag" takes on a value of 1, so I want the entire row deleted such that both the date and the value related to the bank is also deleted. By delete I mean I want the row removed so that the next row "shifts" up so that no empty row appears. Also note that there is also the number 1 under column B, eg, row 201, I do not want to delete those, I only want the rows deleted where exitflag has a value of 1.

    I have written the following code but for some reason I don't think it works (or if it does work, I have to keep running it over and over, it doesn't do what I want in one go):

    Please Login or Register  to view this content.
    Also preferably I would like the code to be a "selection." code rather than specifying a range as I would like to reuse the code on other datasets but with different number of rows.

    Much appreciated for any assistance!
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Deleting Rows using VBA macro

    Hi, TrueTears,

    if you want to use a For Each loop you should build a range to delete and delete that range after you passed the entire area. When it comes to deleting you may use a For Next loop starting from the bottom and working up:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Deleting Rows using VBA macro

    Hi TrueTears,
    as an option
    in your example, try selecting entire columns A:C and run this macro
    Please Login or Register  to view this content.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Deleting Rows using VBA macro

    Hi, TrueTears,

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.vbaexpress.com/forum/show...sing-VBA-macro

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro help with combining data across 2 rows (and deleting non-required rows)
    By InnesMcc in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 05-20-2013, 05:21 AM
  2. Excel 2007 : Deleting Rows Macro
    By Mike74 in forum Excel General
    Replies: 2
    Last Post: 06-23-2010, 03:25 PM
  3. How to make my macro delete rows? It currently hides the rows instead of deleting.
    By Majkataxmk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-20-2010, 01:14 PM
  4. Deleting rows with macro
    By PhilScratchingmyhead in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-29-2006, 01:00 PM
  5. Macro for deleting rows
    By benxprezoise in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-30-2005, 06:40 AM

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