Deleting Empty Rows in Excel VBA

Поділитися
Вставка
  • Опубліковано 3 сер 2024
  • The code for the script is:
    Sub DeleteRows()
    On Error Resume Next
    Range("A3:A" & Worksheets(1).UsedRange.Rows.Count).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub
    If you have any questions, feel free to write them down in the comments.

КОМЕНТАРІ • 33

  • @ElectronicPurine
    @ElectronicPurine 28 днів тому

    You explained each step so well, and I really love your "no hard code" idea!!! Thank you for such a effective tutorial💯🎆

  • @starman9000
    @starman9000 3 роки тому +1

    Hey Nik, I was looking exactly this code, Thank you.

  • @skhussain4965
    @skhussain4965 2 роки тому

    Very helpful, many thanks 😊

  • @x.lpythonamicofficial7714
    @x.lpythonamicofficial7714 3 роки тому

    I'm looking for this code past two month, thanks for it.

    • @FinanceNik
      @FinanceNik  3 роки тому

      Thank you for the warm feedback! Appreciate it

  • @chadiabou-ghayda8276
    @chadiabou-ghayda8276 2 роки тому +1

    Excellent. Many Thanks👌.
    BUT ... it worked on the cells that are totally empty .. the cell that were empty but had a formula in the cell didn't delete .. any help

  • @gopijanjanam985
    @gopijanjanam985 3 роки тому

    This is awesome buddy thank you

  • @soumenroy7907
    @soumenroy7907 3 роки тому

    Excellent...Nik

  • @peterwestin
    @peterwestin 2 роки тому

    Hello - -thank your for a very good video. One question - is it possible to write a macro that deletes empty cells AND empty rows in the same operation?

  • @exclusivelynyc
    @exclusivelynyc 3 роки тому

    Thank you. This is an excellent video. How would I have this run automatically as soon as I paste the data to the worksheet? Also, how could I add another line to remove duplicates at the same time? Thank you so much.

    • @FinanceNik
      @FinanceNik  3 роки тому

      Hey, I'll get into that!

    • @exclusivelynyc
      @exclusivelynyc 3 роки тому

      @@FinanceNik Thank you. I have figured it out. Maybe you can do a video on list of names being added to a sheet that already has names but having excel only add new names on the list if you could understand that. I have a master list but i get another list everyday and want to add only the new names on that list automatically and delete the duplicates. Thanks. Keep doing awesome work.

    • @FinanceNik
      @FinanceNik  3 роки тому

      @@exclusivelynyc Hey, may I ask whether your sheets also include information in terms of a ID, say a customer ID or must the sheet distinguish by first and last name?

    • @exclusivelynyc
      @exclusivelynyc 3 роки тому +1

      @@FinanceNik the data that I need to clean does have an ID number associated with a name but it is not necessary for what I have to do. If it would help to keep the ID number to do what I need to do I can keep it. I hope to distinguish between different names because I need to put each name to a different floor in my building than calculate how many people are on that floor specifically, than how many people are in the building total. Hope you can understand this. Thank you for your help

  • @vitarathiel
    @vitarathiel 2 роки тому

    Hi !
    how to automatically delete empty row / column immediately, after i cut & paste ?

  • @abdulbasha6860
    @abdulbasha6860 3 роки тому +1

    Hi, in code &worksheets(1), do we need to add name of the sheet in bracket () instead of 1

    • @FinanceNik
      @FinanceNik  3 роки тому

      Hey Abdul, there is two different ways of referencing worksheets. You can refer to their name or refer to their position in the worksheets tab. If you want to refer to their name then you have to reference the name in quotation marks, i.e., worksheets("name_of_worksheet"). If you want to reference their position, no quotation marks are needed, i.e., worksheets(3). Thank you for your question. I hope this clarified the issue for you!

    • @abdulbasha6860
      @abdulbasha6860 3 роки тому

      @@FinanceNik thanks for your prompt reply, I will try from my end and let's see whether this will resolve my problem.

  • @michaelw3287
    @michaelw3287 3 роки тому

    Hello, this works great for when entire row is blank but not when the cell in the column is the only blank. Is there a way to fix the code to delete the row if the a cell in the column is blank? Thank you!

    • @FinanceNik
      @FinanceNik  3 роки тому

      Hello Michael, yes there sure is a way. I'll make it my next vid!

    • @michaelw3287
      @michaelw3287 3 роки тому

      @@FinanceNik thank you very much! Your videos are amazingly informative. Have a great day!

  • @babu393
    @babu393 Рік тому

    Is it possible only the some rows rather than entire row.. Expecting reply

  • @tonywillingham8109
    @tonywillingham8109 2 роки тому +1

    How do you deal with the first row, which the auto filter seems to ignore?

    • @FinanceNik
      @FinanceNik  2 роки тому

      Hey Tony, you just start the for loop at i = 1, thus starting at the first row of a worksheet. Hope this helps

  • @TheSnowman4vn
    @TheSnowman4vn 3 роки тому

    hi Nik, what if a row has 1 cell that has data .. example A4-C4 = blank, but D4 has data ?

    • @FinanceNik
      @FinanceNik  3 роки тому +1

      You can essentially choose which row to take as the argument. In your case, if C4 was you criteria cell then the row would be deleted. If you choose D4 as your criteria cell then the row would not be deleted. Hope this helps!

  • @Arjunprasadjr
    @Arjunprasadjr 3 роки тому +1

    I am getting compile error:invalid use of property highlighting Range

    • @FinanceNik
      @FinanceNik  3 роки тому +1

      Hi Arjun, maybe check if there is a minor spelling error somehwere in the code. That might solve it

  • @dannycheung2114
    @dannycheung2114 3 роки тому

    Hi Nik, is it possible to use vlookup function in vba?

    • @FinanceNik
      @FinanceNik  3 роки тому +1

      Hey Danny, yes it sure is. I would recommend recording a macro while doing a vlookup and then copying the code into whatever vba script you would like to do

    • @dannycheung2114
      @dannycheung2114 3 роки тому

      @@FinanceNik great with thanks

    • @htchd0211
      @htchd0211 3 роки тому +1

      Try worksheetfunction .Vlooukup(), all the args are just the same when working on the worksheet.