Forum Discussion

SamFares's avatar
SamFares
Brass Contributor
Nov 14, 2019
Solved

Macro to delete certain cells in several columns depending cell value in a different cell

Hello All,

In the attached Excel sheet, "Input Continuous-Span Beam" tab, I'd like a macro to do the following

when: 

1. Cell B10=2, to delete the cells highlighted in yellow for Span#3,4&5 only.

2. When Cell B10=3, to delete the cells highlighted in yellow for Span#4&5 only.

3. When Cell B10=4, to delete the cells highlighted in yellow for Span#5 only.

4. When Cell B10=5, don't delete anything.

Also I'd like another macro for deleting  cells highlighted in yellow only for  LE Cantilever or RE Cantilever or both Cantilevers data which is right at row 60-65. 

 

Regards,

Sam

  •  

    SamFares

    This code will CLEAR the ranges depending on 2, 3 or 4. Deleting them would screw your entire sheet, I guess.

    Sub ClearSpan()
    
    Dim NoSpansN As Integer
    
    NoSpansN = Range("B10").Value
    
    Select Case NoSpansN
    
        Case 2
            Range("J17:U58").Select
            Selection.Clear
        
        Case 3
            Range("N17:U58").Select
            Selection.Clear
        
        Case 4
            Range("R17:U58").Select
            Selection.Clear
        
    End Select
    
        Range("B10").Select
        
    End Sub

     The next code will clear the contents of the yellow cells in the LE and RE Cantilever sections:

    Sub DeleteLE_RE()
    
        Range("D60:D65,G64,H60,Q60:Q65,T64,U60").Select
        Selection.ClearContents
        
    End Sub

    If this is not what you have in mind, please clarify your needs.

     

2 Replies

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

     

    SamFares

    This code will CLEAR the ranges depending on 2, 3 or 4. Deleting them would screw your entire sheet, I guess.

    Sub ClearSpan()
    
    Dim NoSpansN As Integer
    
    NoSpansN = Range("B10").Value
    
    Select Case NoSpansN
    
        Case 2
            Range("J17:U58").Select
            Selection.Clear
        
        Case 3
            Range("N17:U58").Select
            Selection.Clear
        
        Case 4
            Range("R17:U58").Select
            Selection.Clear
        
    End Select
    
        Range("B10").Select
        
    End Sub

     The next code will clear the contents of the yellow cells in the LE and RE Cantilever sections:

    Sub DeleteLE_RE()
    
        Range("D60:D65,G64,H60,Q60:Q65,T64,U60").Select
        Selection.ClearContents
        
    End Sub

    If this is not what you have in mind, please clarify your needs.

     

    • SamFares's avatar
      SamFares
      Brass Contributor
      I appreciate it and Thank you so much!

      Sam

Resources