Results 1 to 10 of 380

Thread: Appendix Thread. ( Codes for other Threads, etc.) Event Coding Drpdown Data validation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Macro for this Thread post
    https://excelfox.com/forum/showthrea...ll=1#post13423


    Calculate 2% of colum H & column I & considered the greater number between them
    column S should be positive, so don’t considere the no. which are negative
    & if column S is lower than that 2% of column H or Column I (whichever is greater )then put -1
    vba macro will be placed in a seperate file , sheet name can be anything, all files are located in different place
    example
    the U2 cell will become -1 after runing the macro



    Code:
    Sub CalculationByPercentageAndConditionallyPutingTheData() '  https://excelfox.com/forum/showthread.php/2499-calculation-by-percentage-and-conditionally-puting-the-data?p=13423&viewfull=1#post13423
    Rem worksheets info
    '  ap.xls
    Dim Wbap As Workbook
     Set Wbap = Workbooks("ap.xls")
    Dim Wsap As Worksheet
     Set Wsap = Wbap.Worksheets.Item(1)
    Dim Lrap As Long: Let Lrap = Wsap.Range("B" & Wsap.Rows.Count & "").End(xlUp).Row  '   http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim Arrap As Variant: Let Arrap = Wsap.Range("A1:Y" & Lrap & "").Value2
    ' 1b) Evaluate range H and I at 2%   -     Calculate 2% of colum H & column I
    Dim arrH2pc() As Variant, arrI2pc() As Variant
     Let arrH2pc() = Evaluate("=2/100*H2:H" & Lrap & "")
     Let arrI2pc() = Evaluate("=2/100*I2:I" & Lrap & "")
    
    Rem 2
    Dim arrS() As Variant: Let arrS() = Wsap.Range("S1:S" & Lrap & "").Value2
    Dim arrU() As Variant: Let arrU() = Wsap.Range("U1:U" & Lrap & "").Value2
    Dim Cnt As Long
        For Cnt = 2 To Lrap
            If arrS(Cnt, 1) >= 0 Then
            Dim BgstHI As Double           '             colum H & column I & considered the greater number between them
            Let BgstHI = arrH2pc(Cnt - 1, 1)   '                                                                                                                         Cnt - 1  is  because our arrays for the H and I columns start at row 2 , so the indices will be one less than the roe to which they apply . I chose to do this to avoid trying to get 2% of the header , as that would error
                If arrH2pc(Cnt - 1, 1) < arrI2pc(Cnt - 1, 1) Then Let BgstHI = arrI2pc(Cnt - 1, 1) '  If I column is largest, use that, otherwise H will be taken   NOTE: H will be taken if the H and I columnns are equal
                If arrS(Cnt, 1) < BgstHI Then Let arrU(Cnt, 1) = -1
            Else ' S < 0
            '  column S should be positive, so don’t considere the no. which are negative
            End If
        Next Cnt
        
    Rem 3 paste out
     Let Wsap.Range("U1:U" & Lrap & "").Value2 = arrU()
    End Sub

    arrHISU.JPG : https://imgur.com/uunxENf
    Attachment 2954




    Share ‘macro.xlsm’ : https://app.box.com/s/599q2it3uck3hfwm5kscmmgtn0be66wt
    Share ‘ap.xls’ : https://app.box.com/s/pq6nqkfilk2xs5lf19ozcpx081rp47vs
    Attached Images Attached Images

Similar Threads

  1. Replies: 189
    Last Post: 02-06-2025, 02:53 PM
  2. Replies: 293
    Last Post: 09-24-2020, 01:53 AM
  3. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  4. Restrict data within the Cell (Data Validation)
    By dritan0478 in forum Excel Help
    Replies: 1
    Last Post: 07-27-2017, 09:03 PM

Posting Permissions

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