+ Reply to Thread
Results 1 to 18 of 18

If one cell in line turn empty then entire line turns empty

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    If one cell in line turn empty then entire line turns empty

    Hello everyone.

    I would like to get some help.

    I have a very large worksheet and I would like if, as example, if I delete content of 1 cell in specific line to entire line turn empty together.

    How do I do that?

    I was thinking in adding a button for "update" the worksheet before closing...

    Thanks in advance.

  2. #2
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    You can run a loop that checksfor empty cells and then deletes the entire row. It might look something like this:
    Sub clearlines()
    
    Dim empty as Range
    
    For Each empty in Range("A1:A2")
    
    If empty.FormulaR1C1 = "" Then empty.EntireRow.ClearContents
    
    Next empty
    
    End Sub
    Last edited by LaffyAffy13; 07-18-2013 at 11:09 AM. Reason: Changed info to "Clear Contents" instead of "Delete"
    ~~LaffyAffy13~~

    If I have helped you solve your problem, please be sure to click at the bottom left of my post.

    Thanks.

  3. #3
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    Hello, thank you for your patience and attention, but if possible I would like instead of delete the row, to just clear content on rest of cells of this row...

    Would it be possible?

    Regards.

  4. #4
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    And then add the macro to your "Update" button.

  5. #5
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Of course! Check the code, I edited it.

  6. #6
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    Quote Originally Posted by LaffyAffy13 View Post
    Of course! Check the code, I edited it.
    Thank you very much!

    But how do I change R1C1 for work only in the range B4:K3000? And if not much work to ignore lines that contain formulas? (is it called formula in english? not sure...)

  7. #7
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Yes, they are called formulas. You want to clear the contents of any row that contains an empty cell, specifically in the range "B4:K3000", but ignore all rows with any cells that contain a formula? Am I understanding that correctly?

  8. #8
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    Quote Originally Posted by LaffyAffy13 View Post
    Yes, they are called formulas. You want to clear the contents of any row that contains an empty cell, specifically in the range "B4:K3000", but ignore all rows with any cells that contain a formula? Am I understanding that correctly?
    No I want macro to ignore specific cells which contain formulas. I have uploaded an sample sheet for better understanding.

    Link: http://temp-share.com/show/dPf3UCA5W

    In C column if you click from C4 and down you'll see there's a formula for changing suppliers name. I didn't wanted it to be changed...

    Thank you again.

  9. #9
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    I'm working on it, give me like 15 minutes.

  10. #10
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Alright. I noticed the code deleted your purple chart contents as well, so I have fixed that. Also, I place the formula into the cells C4 to C3000 after they have been cleared. Is this okay? Sorry it is so long, I had to find a way to save your purple chart.
    Sub Botão1_Clique()
    
    Dim vazia As Range, número_da_linha As Integer
    
    Application.ScreenUpdating = False
    
    número_da_linha = 4
    
        For Each vazia In Range("B4:B3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("B" & número_da_linha) _
                , Range("B" & número_da_linha).Offset(, 9)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("D4:D3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("D" & número_da_linha).Offset(, -2) _
                , Range("D" & número_da_linha).Offset(, 7)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("E4:E3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("E" & número_da_linha).Offset(, -3) _
                , Range("E" & número_da_linha).Offset(, 6)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("F4:F3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("F" & número_da_linha).Offset(, -4) _
                , Range("F" & número_da_linha).Offset(, 5)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("G4:G3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("G" & número_da_linha).Offset(, -5) _
                , Range("G" & número_da_linha).Offset(, 4)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("H4:H3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("H" & número_da_linha).Offset(, -6) _
                , Range("H" & número_da_linha).Offset(, 3)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("I4:I3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("I" & número_da_linha).Offset(, -7) _
                , Range("I" & número_da_linha).Offset(, 2)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("J4:J3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("J" & número_da_linha).Offset(, -8) _
                , Range("J" & número_da_linha).Offset(, 1)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("K4:K3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("K" & número_da_linha).Offset(, -9) _
                , Range("K" & número_da_linha)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    Range("C4").FormulaR1C1 = "=IF(RC[-1]=1, ""Cablena VW"", IF(RC[-1]=2, ""Cablena YH"", IF(RC[-1]=3, ""Capri"", IF(RC[-1]=4, ""Sakaguchi Industrial"", IF(RC[-1]=5, ""Metalurgica Sakaguchi"", IF(RC[-1]=6, ""Winflex"", IF(RC[-1]=7, ""Littelfuse"",IF(RC[-1]=8, ""Loopmol"", IF(RC[-1]=9, ""ITW"", IF(RC[-1]=10, ""Newtoy"", IF(RC[-1]=11, ""Kluber"")))))))))))"
    Range("C4").Select
    Selection.AutoFill Destination:=Range("C4:C" & número_da_linha), Type:=xlFillDefault
    
    Application.ScreenUpdating = True
    
    End Sub

  11. #11
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    Oh my God! You're great!

    It seemed so easy to you for making all this long code!

    I would like to ask you one more favor if possible. Could you imput after the functions notes like 'here I change the cells colors and so on?

    Because I really would like to learn VBA and for that I would like to understand what each thing is doing in the code.

    But just if you have time.

    Thank you so much!

  12. #12
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Hope that helps!

  13. #13
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    Quote Originally Posted by LaffyAffy13 View Post
    Hope that helps!
    Thank you!

    I know my main question is already solved but I thought in not creating a new thread for one more question about same worksheet.

    You see next to columns that should be filled with dates there are a small cell for numbers which goes like this:

    If date of billing is like 9/21/13 then it should be filled with number 9 which means month 9 as mentioned on table of caption. At this moment it will be filled manually since I could not make a formula for IF in these cells because of date. Would you know by chance a easy way to automatically fill the number of month right after imputting the date on month cell?

    Kind regards!

  14. #14
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Ignore this, I tried to delete it but don't know how.
    Last edited by LaffyAffy13; 07-18-2013 at 04:59 PM.

  15. #15
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    Sub Botão1_Clique()
    
    Dim vazia As Range, número_da_linha As Integer
    
    Application.ScreenUpdating = False 
    'This makes you unable to see what is happening. It speeds up the process by allowing your computer to run the program without displaying anything.
    
    número_da_linha = 4
    This sets the variable equal to 4. You need the "_" to keep all of the words together and considered as one whole word, not 3 individual ones.
        
    For Each vazia In Range("B4:B3000")
    'This basically says "look for each range(also considered a cell) within the area 'B4:B3000'"
    
            If vazia.FormulaR1C1 = "" Then Range(Range("B" & número_da_linha) _
                , Range("B" & número_da_linha).Offset(, 9)).ClearContents
    'This is one line of code, separated into two lines (so that you can read all of it without scrolling) by the "_". To better understand this method, search the internet.
    'This code says "if the current cell's formula is blank or empty, then clear the contents of the range 'B?' to 'K?'" and the '?' is whichever number 'número_da_linha' is equal to.
            número_da_linha = número_da_linha + 1
    'This raises número_da_linha from 4 to 5, 5 to 6, and so on. it is how the program clears all of the lines, but it does so one line at a time. this is why i used "Application.ScreenUpdating = False"
    
        Next vazia
    'This pushes the path of the code back to the line "For Each vazia in Range...". It allows the code to go to cell "B?" and continue the trend until cell "B3000"
    
    número_da_linha = 4
    
        For Each vazia In Range("D4:D3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("D" & número_da_linha).Offset(, -2) _
                , Range("D" & número_da_linha).Offset(, 7)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("E4:E3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("E" & número_da_linha).Offset(, -3) _
                , Range("E" & número_da_linha).Offset(, 6)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("F4:F3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("F" & número_da_linha).Offset(, -4) _
                , Range("F" & número_da_linha).Offset(, 5)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("G4:G3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("G" & número_da_linha).Offset(, -5) _
                , Range("G" & número_da_linha).Offset(, 4)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("H4:H3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("H" & número_da_linha).Offset(, -6) _
                , Range("H" & número_da_linha).Offset(, 3)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("I4:I3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("I" & número_da_linha).Offset(, -7) _
                , Range("I" & número_da_linha).Offset(, 2)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("J4:J3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("J" & número_da_linha).Offset(, -8) _
                , Range("J" & número_da_linha).Offset(, 1)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    número_da_linha = 4
    
        For Each vazia In Range("K4:K3000")
            If vazia.FormulaR1C1 = "" Then Range(Range("K" & número_da_linha).Offset(, -9) _
                , Range("K" & número_da_linha)).ClearContents
            número_da_linha = número_da_linha + 1
        Next vazia
    
    Range("C4").FormulaR1C1 = "=IF(RC[-1]=1, ""Cablena VW"", IF(RC[-1]=2, ""Cablena YH"", IF(RC[-1]=3, ""Capri"", IF(RC[-1]=4, ""Sakaguchi Industrial"", IF(RC[-1]=5, ""Metalurgica Sakaguchi"", IF(RC[-1]=6, ""Winflex"", IF(RC[-1]=7, ""Littelfuse"",IF(RC[-1]=8, ""Loopmol"", IF(RC[-1]=9, ""ITW"", IF(RC[-1]=10, ""Newtoy"", IF(RC[-1]=11, ""Kluber"")))))))))))"
    'This sets the value of "C4" equal to your original formula. The "RC[-1]" refers to "one column to the left of the current cell". R = rows, C = columns. If i have R[-4]C[7] that refers to "4 rows above and 7 columns to the right of the current cell"
    
    Range("C4").Select
    'selects "C4"
    
    Selection.AutoFill Destination:=Range("C4:C" & número_da_linha), Type:=xlFillDefault
    'Makes all cells in column C have the same formula and format as "C4"
    
    Application.ScreenUpdating = True
    'lets you see whats happening again
    
    End Sub

  16. #16
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    I'll see if I can figure it out.
    Last edited by LaffyAffy13; 07-18-2013 at 04:50 PM.

  17. #17
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: If one cell in line turn empty then entire line turns empty

    I do not think that is easily possible. Dates are not considered text, they are considered numbers. For instance, today's date is equivalent to 41473. So I can't grab anything from "41473" that will give you the current month because I do not know where excel gets these numbers from. But if you read into it, you may be able to figure it out. I am sorry that I can't help you with this. You may consider creating a new thread and asking this question there. Someone else may know how to do this. If you do, you can provide a link to this thread, but it does not match this thread's contents, so I would just create a new one and provide the same link you gave me. I hope you figure things out!

  18. #18
    Registered User
    Join Date
    07-18-2013
    Location
    Sao Paulo
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: If one cell in line turn empty then entire line turns empty

    No problem, you already helped me alot.

    Thank you very much!

+ 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. Check range A10 to A45 and if cell not empty then same line in B must have value
    By CAVA30 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-08-2013, 09:25 PM
  2. Need to delete the empty line
    By hisham_a_j in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 05-28-2012, 05:22 AM
  3. Paste in next empty line
    By Doolafs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2010, 07:24 AM
  4. Line chart-lot of empty cell
    By missing in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 11-14-2006, 06:42 AM
  5. If value in column is yes; entire line turns red
    By Geert_Pick in forum Excel General
    Replies: 2
    Last Post: 03-03-2006, 03:50 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