Results 1 to 2 of 2

Thread: Can the attachment be completely turned into VBA? (No More Formula)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    It is very difficult to understand you. Your English is very bad, so I must try to guess what you want.

    I give you two solutions

    Solution1 With formulas
    Quote Originally Posted by wk9128 View Post
    ...
    When inserting a row, there are formulas at the top and bottom, and the formula for inserting the row is gone.
    It will not be gone. I will put it back in!

    In ThisWorkbook code module
    Code:
    Option Explicit
    Private Sub Workbook_Open()
     Let Sheet1.UsdRws = Worksheets.Item(1).UsedRange.Rows.Count
    End Sub
    In worksheet object code module
    Code:
    Option Explicit
    Public UsdRws As Long
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Me.UsedRange.Rows.Count = UsdRws + 1 Then
         Let Application.EnableEvents = False
         Let Range("J" & Target.Row & "").Value = "=IF(OR(RC[-3]="""",RC[-1]=""""),"""",RC[-3]*RC[-1])"
         Let Application.EnableEvents = True
        Else
        End If
    End Sub
    Share 'help0828WithFormula.xlsm' : https://app.box.com/s/2pex879xrgresupqmg4r54wp3e9a016f




    Solutiuon2 No Formulas
    When a row is added, ( or any change made in the worksheet) , the calculation is done, and the sum value pasted to the Total row

    In worksheet object code module
    Code:
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Lr As Long
     Let Lr = Range("J" & Rows.Count & "").End(xlUp).Row - 1
    Dim arrDta() As Variant
     Let arrDta() = Range("G16:J" & Lr & "").Value2
    Dim Cnt As Long
        For Cnt = 1 To UBound(arrDta(), 1) Step 1
        Dim SumJ As Double
            If arrDta(Cnt, 1) <> "" Then
             Let SumJ = SumJ + arrDta(Cnt, 1) * arrDta(Cnt, 4)
            Else
            ' empty row
            End If
        
        Next Cnt
     Let Application.EnableEvents = False
     Let Range("J" & Lr + 1 & "").Value2 = SumJ
     Let Application.EnableEvents = True
    End Sub
    Share 'help0828NoFormula.xlsm' : https://app.box.com/s/ewufwr7p589xf1rq0pt8qys26j6crdxq


    Alan
    Attached Files Attached Files
    Last edited by DocAElstein; 08-29-2020 at 03:52 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 0
    Last Post: 01-29-2020, 05:05 PM
  2. Replies: 3
    Last Post: 02-09-2019, 08:44 AM
  3. VBA Macro for Bulks and an attachment
    By UsmanKhalid in forum Excel Help
    Replies: 1
    Last Post: 01-27-2014, 12:13 PM
  4. Replies: 2
    Last Post: 07-02-2013, 02:36 PM
  5. Replies: 1
    Last Post: 10-28-2011, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •