logo elektroda
logo elektroda
X
logo elektroda

Excel VBA Macro for Deleting Rows Containing Values 1224, 1228, 1232 in Column M

Mikolaj66 12282 10
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16663620
    Mikolaj66
    Level 1  
    Hello
    I need help writing the excel macro

    In the M column I have 10 types of repeating, mixed numbers.
    I would like the macro to find rows in the M column with the values 1224, 1228 and 1232
    Then they removed the entire rows, that is, all data in all columns in the row that contains these numbers.
    But this was the case there were no empty lines, i.e. after deleting the data moves to the places of empty lines.
    The document is large because over 700,000 rows, columns from A to R
  • ADVERTISEMENT
  • Helpful post
    #2 16663814
    JRV
    VBA, Excel specialist
    Code: text
    Log in, to see the code
  • #3 16885193
    ag851104
    Level 7  
    Hello
    I am beginner and more likely this is my crawling with VBA. I have a similar question because the code doesn't work. I have a table in column A and B with 20 rows and I would like to delete the entire row and not create an empty space if the following words appear in column A
    Based on the code that is given, I wanted to create a similar one
    I would ask for help

    Sub delete ()
    Application.ScreenUpdating = False
    ow = Cells (Rows.Count, "A"). End (xlUp). Row
    For r = ow To 1 Step -1
    If Cells (r, "A") = Centala Or Cells (r, "A") = Kiev Or Cells (r, "A") = Lviv Or Cells (r, "A") = Germany Or Cells (r, " A ") = RKS Kliszczak Or Cells (r," A ") = RKS Krupski Or Cells (r," A ") = SDS Błędowska Or Cells (r," A ") = Sopot Or Cells (r," A ") = Terespol Or Cells (r, "A") = Ukraine Spec Then Rows (r). Delete
    Next
    Application.ScreenUpdating = True
    End Sub
  • ADVERTISEMENT
  • #4 16885261
    JRV
    VBA, Excel specialist
    First read in the basics what a variable, constant, number or string is in VBA
  • ADVERTISEMENT
  • #5 16885402
    cbrman
    Level 27  
    Text values (string) are enclosed in quotation marks in the code.
  • #6 16886166
    ag851104
    Level 7  
    Czyli wystarczy ze dodam cudzyslow i bedzie dzialac.?
    Z gory dziekuje za pomoc:)
    Ania

    Dodano po 13 [godziny] 35 [minuty]:

    Takie cos?
    Sub usuniecie()
    Application.ScreenUpdating = False
    ow = Cells(Rows.Count, "A").End(xlUp).Row
    For r = ow To 1 Step -1
    If Cells(r, "A") = "Centala" Or Cells(r, "A") = "Kijów" Or Cells(r, "A") = "Lwów" Or Cells(r, "A") = "Niemcy" Or Cells(r, "A") = "RKS Kliszczak" Or Cells(r, "A") = "RKS Krupski" Or Cells(r, "A") = "SDS Błędowska" Or Cells(r, "A") = "Sopot" Or Cells(r, "A") = "Terespol" Or Cells(r, "A") = "Ukraina Spec"
    Then Rows(r).Delete
    Next
    Application.ScreenUpdating = True
    End Sub
  • #7 17639334
    joakao
    Level 2  
    Hello

    I apologize for reheating the topic but I would like to modify the code below so that it does not delete the line but its contents, i.e. changing Delete to Clear, and then copying the table under the empty line and pasting it one line above.
    Can anyone suggest how to do this?
    It is probably trivial but vba is a hard topic for me ...

    Thank you in advance for your help

    JRV wrote:
    Code: text
    Log in, to see the code
  • ADVERTISEMENT
  • #8 17668491
    artur093
    Level 7  
    joakao wrote:
    Hello

    I apologize for reheating the topic but I would like to modify the code below so that it does not delete the line but its contents, i.e. changing Delete to Clear, and then copying the table under the empty line and pasting it one line above.
    Can anyone suggest how to do this?
    It is probably trivial but vba is a hard topic for me ...

    Thank you in advance for your help

    JRV wrote:
    Code: text
    Log in, to see the code


    Do you mean copying one cell below or the whole row?
    I did for one cell:
    Code: VBScript
    Log in, to see the code
  • #9 17669478
    kinggustav
    Level 27  
    But why do that? What do you want to get, because deleting the poem and deleting the content with the copy of what below does in my opinion does the same, just a little slower.
  • #10 17669480
    joakao
    Level 2  
    Hi

    I mean all the full lines below and pasting this range one line above.
    I have changed the code a bit for my needs and now it looks like the following, selects and copies 1000 lines (here I would prefer that it selects all full ones) after the first empty but I miss pasting the copied range one line above.

    Sub delete ()
    Application.ScreenUpdating = False
    ow = Cells (Rows.Count, "B"). End (xlUp). Row
    For r = ow To 1 Step -1
    If Cells (r, "B") = Sheets ("Production"). Range ("G1"). Value Then Rows (r). Clean
    If Cells (r, "B") = "" Then Range (Rows (r + 1), Rows (r + 1000)). Select
    Selection.Copy


    Next
    Application.ScreenUpdating = True

    End Sub
  • #11 17684652
    MistrzJaśko
    Level 6  
    If you need to skip a line use the .OffSet function :)

Topic summary

The discussion revolves around creating an Excel VBA macro to delete entire rows in a spreadsheet where the M column contains specific values (1224, 1228, 1232). A user seeks assistance in writing this macro, emphasizing the need to avoid leaving empty rows after deletion. A provided solution includes a VBA script that iterates through the rows in reverse order, checking for the specified values and deleting the corresponding rows. Additional responses address related queries about modifying the code to clear contents instead of deleting rows, and suggestions for copying and pasting data to fill gaps left by deletions. The conversation highlights common issues faced by beginners in VBA programming and the importance of proper syntax, such as enclosing string values in quotation marks.
Summary generated by the language model.
ADVERTISEMENT