+ Reply to Thread
Results 1 to 8 of 8

vba delete rows in another workbook

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    texas usa
    MS-Off Ver
    Excel 2010
    Posts
    70

    vba delete rows in another workbook

    Attached 2 workbooks
    I run controlbutton2 in workbook "sheetchange.xlsm with the intent
    of deleting rows in workbook "sheetchangedata.xlsx that do not
    contain zused or zconsignment in column A.

    The coding does make "sheetchangedata.xlsx the active workbook
    and "inventory report all stores" the active worksheet.
    However, when I run commandbutton2 the correct rows are
    deleted - but in sheetchange.xlsm not in "sheetchangedata.xlsx"
    despite the fact that "sheetchangedata.xlsx" is active.
    question - why aren't the rows deleted in the active workbook and active worksheet
    question - can I change the line that deletes the entire row so that workbook and sheet
    ("sheetchangedata.xlsx " and "inventory report all stores" are specified in that line.

    Thanks Carroll
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: vba delete rows in another workbook


    As in a worksheet module any range without any sheet reference is relative to the worksheet of this module and not to the active sheet
    so just add the workbook and sheet references for any range to be deleted …

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    texas usa
    MS-Off Ver
    Excel 2010
    Posts
    70

    Re: vba delete rows in another workbook

    This is the delete row line If Not (Range("A" & i).Value Like "*ZUSED*" Or Range("A" & i).Value Like "*ZCONSIGNMENT*") Then Rows(i).Delete

    Ok, so the answer to my second question is yes.
    I'm not sure how to change this line to specify the workbook/sheet.
    Also, if I change this line to specify workbook/worksheet, then
    I guess there is no reason to do all the coding to make "sheetchangedata.xlsx and sheet " inventory report all stores" active.

    I guess I don't understand what "active" does.
    Thanks for your help.
    Carroll

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: vba delete rows in another workbook

    Try change to
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-10-2012
    Location
    texas usa
    MS-Off Ver
    Excel 2010
    Posts
    70

    Re: vba delete rows in another workbook

    Jindon
    Thanks for the code - works great
    I have tried to add code to make the like operator case insensitive, but have been unsuccessful.
    Have tried option compare and others but no luck
    Appreciate any help
    carroll

  6. #6
    Registered User
    Join Date
    09-10-2012
    Location
    texas usa
    MS-Off Ver
    Excel 2010
    Posts
    70

    Re: vba delete rows in another workbook

    Jindon
    I was successful with the option compare method - below
    ' Set the string comparison method to Text. Makes case insensitive
    Option Compare Text ' That is, "AAA" is equal to "aaa".

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: vba delete rows in another workbook

    OK, glad you found a way and thanks for the rep.

    Just in case you want to compare case sensitive in other routine within the same module as I don't like Option statement.
    1) Use UCase
    Please Login or Register  to view this content.
    2) Use InStr function
    Please Login or Register  to view this content.
    HTH


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  8. #8
    Registered User
    Join Date
    09-10-2012
    Location
    texas usa
    MS-Off Ver
    Excel 2010
    Posts
    70

    Re: vba delete rows in another workbook

    Thanks for the other options
    Carroll

+ 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] delete blank rows in new Workbook with VBA
    By QuantumSquirrel in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-24-2020, 01:32 PM
  2. Replies: 2
    Last Post: 08-07-2017, 02:37 PM
  3. Replies: 1
    Last Post: 08-07-2017, 01:27 PM
  4. Delete all rows in workbook with same title
    By dbe89 in forum Excel General
    Replies: 3
    Last Post: 07-16-2013, 12:58 AM
  5. [SOLVED] Delete Rows in entire workbook.
    By jhall488 in forum Excel Programming / VBA / Macros
    Replies: 54
    Last Post: 11-12-2012, 12:49 PM
  6. Delete rows from another workbook
    By psatkar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2006, 05:28 AM
  7. [SOLVED] delete empty rows in workbook
    By TooN in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-10-2006, 06:25 AM

Tags for this Thread

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