+ Reply to Thread
Results 1 to 21 of 21

delete row and enter formula

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    delete row and enter formula

    Hi to all
    This macro
    Option Explicit
    
    
    '=SE.ERRORE(CONFRONTA(D4;articoli!B6:B8000;0)+5;0)
    
    
    Sub Canc_A_O_1_riga_new() 'mine
    
    
    
    Dim Nriga As Long
    Dim n As Long
       'Dim x As Long
    Dim avviso As String
    
    Dim SComm1, SComm2 As String
    
    
    
    SComm1 = Sheets("nuovo_articolo").Range("D4").Value
    SComm2 = Sheets("nuovo_articolo").Range("F4").Value
    
    
    
    
    If ActiveSheet.Range("F4").Value = 0 Then
    avviso = MsgBox("Sign. " & Environ("UserName") & Chr(13) & "inserisci un'articolo da eliminare," & Chr(13) & _
    "l'articolo inserito < " & SComm2 & " > " & Chr(13) & _
    "non è presente in foglio < articoli >!", _
      vbInformation + vbOKOnly + vbDefaultButton2, "AVVISO")
    Exit Sub
    End If
    
    
    
    avviso = MsgBox("elimino l'articolo < " & SComm1 & " > in riga < " & SComm2 & _
    " > ? ", vbYesNo + vbExclamation, "ATTENZIONE!")
    If avviso = vbNo Then
    Exit Sub
    End If
    
    
    
    
    Sheets("articoli").Select
    
    
    
    
    ActiveSheet.Unprotect "123456"
    
    Application.ScreenUpdating = False
    
    Nriga = SComm2
    
    Application.EnableEvents = False
                   
    
    Range(Cells(Nriga, "B"), Cells(Nriga, "Q")).ClearContents
    
    Application.EnableEvents = True
    
    
    
    
    Call rimetti_formula
    
    'Call formula_2
    
    
    ActiveSheet.Protect "123456"
    
    
    
    Sheets("nuovo_articolo").Select
    
    
    Sheets("nuovo_articolo").Range("D4").Select
    Selection.ClearContents
    
    
    Application.ScreenUpdating = True
    
    
    End Sub
    deletes the row sheet "articoli" inserted in the sheet "nuovo articolo" cell D4.
    after deleting the row the formulas of the deleted row are inserted with this macro

    Call rimetti_formula

    this macro puts the formulas back across the range and is very slow.
    this macro is possible only for the deleted row?
    I hope I have explained
    thank you
    john
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    You could just clear the contents instead of replacing the formulas again.


    Sub Canc_A_O_1_riga_new()
        Dim sh As Worksheet
        Dim r As Long, fnd As String
    
        fnd = Sheets("nuovo_articolo").Range("D4").Value
        Set sh = Sheets("articoli")
        With sh
            r = .Columns(2).Find(fnd).Row
            .Range("B" & r).Range("A1,D1:H1,N1:P1").ClearContents
        End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Hi davesexcel your macro work well.
    I added a sheet "ordina_mail" to the workbook and request a change.
    if the same row deleted with the macro is also present in the sheet "ordina_mail" delete this too
    thank you
    john
    Attached Files Attached Files

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    You can add this line to your code.

        Sheets("ordina_mail").Columns(2).Find(fnd).EntireRow.Delete

  5. #5
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Thanks you davesexcel.
    A greeting
    john

  6. #6
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Hi,
    I inserted the change to the macro.

    '---------------------------------------------------------------------------------------
    'elimina riga foglio ordina_mail
    
     Sheets("ordina_mail").Select
     Sheets("ordina_mail").Unprotect "123456"
    
    
     fnd = Sheets("inserisci_elimina_articolo").Range("D4").Value
    
            
    Sheets("ordina_mail").Columns(2).Find(fnd).EntireRow.ClearContents
        
    Sheets("ordina_mail").Protect "123456"
    
    '---------------------------------------------------------------------------------------
    It almost works well

    if D4

    fnd = Sheets("inserisci_elimina_articolo").Range("D4").Value

    is not present in the sheet "ordina_mail"

    Sheets("ordina_mail").Columns(2).Find(fnd).EntireRow.ClearContents

    it gives an error.

    I intered .EntireRow.ClearContents
    Sheets("ordina_mail").Columns(2).Find(fnd).EntireRow.ClearContents
    because the macro was deleting formulas
    and to delete blank rows there is this macro

    '---------------------------------------------------------------------------------------
    'elimina righe vuote foglio ordina_mail con ordina crescente
    
    'Dim RngArr, i As Long
    
    Sheets("ordina_mail").Select
    Sheets("ordina_mail").Unprotect "123456"
    
    
      'RngArr = Array("A2:H31", "A32:H61", "A62:H86")
    RngArr = Array("A3:L150")
    
    
    For i = LBound(RngArr) To UBound(RngArr)
        Range(RngArr(i)).Sort Range(RngArr(i)).Cells(12), xlAscending 'ordina per colonna 12/L
    Next i
    
    Sheets("ordina_mail").Protect "123456"
    
    '--------------------------------------------------------------------------------------
    I hope I have explained.
    Attached Files Attached Files

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    There was no formula in your sheet email sheet so I wasn't too concerned about it.
    Try this.
    With Sheets("ordina_mail")
        Set fRng = .Columns(2).Find(fnd)
        If Not fRng Is Nothing Then
            .Unprotect "123456"
            .Range("A" & fRng.Row).Range("A1,B1,F1").ClearContents
            .Protect "123456"
        End If
    End With

    The one line will help you decide what cells to clear from the found row.
    Once you run it you will see how it works.

  8. #8
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Undefined variable compilation error

    fRng
    
    '---------------------------------------------------------------------------------------
    'elimina riga foglio ordina_mail
     
    fnd = Sheets("inserisci_elimina_articolo").Range("D4").Value
    
    With Sheets("ordina_mail")
        Set fRng = .Columns(2).Find(fnd)
        If Not fRng Is Nothing Then
            .Unprotect "123456"
            .Range("A" & fRng.Row).Range("A1,B1,F1").ClearContents
            .Protect "123456"
        End If
    End With
    
    '---------------------------------------------------------------------------------------
    Last edited by AliGW; 02-12-2021 at 08:27 AM.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    Yep, you need to dim fRng as range at the top.

  10. #10
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    '---------------------------------------------------------------------------------------
    'elimina riga foglio ordina_mail
     
    fnd = Sheets("inserisci_elimina_articolo").Range("D4").Value
    
    'Dim fRng As Range
    
    With Sheets("ordina_mail")
        Set fRng = .Columns(2).Find(fnd)
        If Not fRng Is Nothing Then
            .Unprotect "123456"
            .Range("A" & fRng.Row).Range("L1").ClearContents
            .Protect "123456"
        End If
    End With
    
    '---------------------------------------------------------------------------------------
    entere row
    .Range("A" & fRng.Row).Range("L1").ClearContents
    not work
    Last edited by john_cash; 02-11-2021 at 03:19 PM.

  11. #11
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Ops

    .Range("A" & fRng.Row).Range("A1:L1").ClearContents

    With Sheets("ordina_mail")
        Set fRng = .Columns(2).Find(fnd)
        If Not fRng Is Nothing Then
            .Unprotect "123456"
            .Range("A" & fRng.Row).Range("A1:L1").ClearContents
            .Protect "123456"
        End If
    End With

  12. #12
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    Are you asking a question?

  13. #13
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    It's this correct for the whole row?

    .Range("A" & fRng.Row).Range("A1:L1").ClearContents

  14. #14
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    Is that what the code looks like in post 7?

  15. #15
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Hi,
    there are no formulas in the sheet "ordina_mail" and the macro must delete the contents of the whole row

  16. #16
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    frng.entirerow.delete
    Experiment with the code
    Last edited by davesexcel; 02-12-2021 at 08:02 AM.

  17. #17
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: delete row and enter formula

    What happens when you try it?

  18. #18
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    492

    Re: delete row and enter formula

    Delete entere row

+ 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. VBA delete cell value and enter new value
    By ioncila in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2016, 05:17 AM
  2. [SOLVED] How to delete an ENTER on a cell
    By pccamara in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-21-2016, 07:54 AM
  3. With VBA Enter Ctrl Shift Enter For Array Formula
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-17-2013, 09:02 AM
  4. [SOLVED] How do I enter a formula that will delete a line when a cell = 0?
    By Jen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-11-2006, 01:25 PM
  5. [SOLVED] Add or Delete row as per enter
    By Tiya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2005, 02:00 PM
  6. Replies: 2
    Last Post: 10-20-2005, 05:05 PM
  7. Determine if cell was modified by Enter , Paste or Delete
    By Randy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2005, 12:06 PM

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