Page 16 of 56 FirstFirst ... 6141516171826 ... LastLast
Results 151 to 160 of 554

Thread: Tests Copying pasting Cliipboard issues. and otes on API stuff

  1. #151
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    In support of this Thread:
    http://www.excelfox.com/forum/showth...Paste-by-a-Vba

    If column E of ap.xls matches with column A of leverage.xlsx then copy column E of leverage.xlsx and paste it to column Z of ap.xls

    Before:
    _____ Workbook: ap.xls ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    Z
    1
    AccountId EntityName Exchg-Seg Symbol
    2
    WC5758 NSE TCS
    3
    WC5758 NSE SRTRANSFIN
    4
    WC5758 NSE MARICO
    5
    WC5758 NSE M&MFIN
    6
    WC5758 NSE 20MICRONS
    7
    WC5758 NSE CONCOR
    8
    WC5758 NSE COALINDIA
    9
    WC5758 NSE BOSCHLTD
    10
    WC5758 NSE BERGEPAINT
    11
    WC5758 NSE 5PAISA
    12
    WC5758 NSE TATAELXSI
    13
    WC5758 NSE HINDPETRO
    14
    WC5758 NSE DISHTV
    15
    Worksheet: ap-Sheet1

    _____ Workbook: LEVERAGE1.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    1
    Stock Name pro times ultimate times
    2
    20MICRONS EQ INE144J01027
    19
    26
    36.35
    3
    TCS EQ INE253B01015
    19
    26
    13.5
    4
    3IINFOTECH EQ INE748C01020
    29
    39
    2.05
    5
    3MINDIA EQ INE470A01017
    48
    64
    21299
    6
    5PAISA EQ INE618L01018
    31
    41
    129.5
    7
    63MOONS EQ INE111B01023
    30
    40
    99.15
    8
    8KMILES EQ INE650K01021
    27
    36
    56.5
    9
    Worksheet: Sheet1

    If column E of ap.xls matches with column A of leverage.xlsx then copy column E of leverage.xlsx and paste it to column Z of ap.xls

    After
    example
    cell E2 of ap.xls matches with column A3 of leverage.xlsx then copy E3 of leverage.xlsx and paste it to Z2 of ap.xls



    _____ Workbook: ap.xls ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    Z
    1
    AccountId EntityName Exchg-Seg Symbol
    2
    WC5758 NSE TCS
    25.823112
    3
    WC5758 NSE SRTRANSFIN
    4
    WC5758 NSE MARICO
    5
    WC5758 NSE M&MFIN
    6
    WC5758 NSE 20MICRONS
    25.823112
    7
    WC5758 NSE CONCOR
    8
    WC5758 NSE COALINDIA
    9
    WC5758 NSE BOSCHLTD
    10
    WC5758 NSE BERGEPAINT
    11
    WC5758 NSE 5PAISA
    40.795512
    12
    WC5758 NSE TATAELXSI
    13
    WC5758 NSE HINDPETRO
    14
    WC5758 NSE DISHTV
    Worksheet: ap-Sheet1
    Attached Files Attached Files

  2. #152
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    For http://www.excelfox.com/forum/showth...ll=1#post11436

    Before:
    _____ Workbook: ap.xls ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    Z
    1
    AccountId EntityName Exchg-Seg Symbol
    2
    WC5758 NSE TCS
    3
    WC5758 NSE SRTRANSFIN
    4
    WC5758 NSE MARICO
    5
    WC5758 NSE M&MFIN
    6
    WC5758 NSE 20MICRONS
    7
    WC5758 NSE CONCOR
    8
    WC5758 NSE COALINDIA
    9
    WC5758 NSE BOSCHLTD
    10
    WC5758 NSE BERGEPAINT
    11
    WC5758 NSE 5PAISA
    12
    WC5758 NSE TATAELXSI
    13
    WC5758 NSE HINDPETRO
    14
    WC5758 NSE DISHTV
    Worksheet: ap-Sheet1

    _____ Workbook: LEVERAGE1.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    Stock Name pro times ultimate times
    2
    20MICRONS EQ INE144J01027
    19
    26
    36.35
    3
    TCS EQ INE253B01015
    19
    26
    13.5
    4
    3IINFOTECH EQ INE748C01020
    29
    39
    2.05
    5
    3MINDIA EQ INE470A01017
    48
    64
    21299
    6
    5PAISA EQ INE618L01018
    31
    41
    129.5
    7
    63MOONS EQ INE111B01023
    30
    40
    99.15
    8
    8KMILES EQ INE650K01021
    27
    36
    56.5
    Worksheet: Sheet1

    After:
    _____ Workbook: ap.xls ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    Z
    1
    AccountId EntityName Exchg-Seg Symbol
    2
    WC5758 NSE TCS
    25.823112
    3
    WC5758 NSE SRTRANSFIN
    4
    WC5758 NSE MARICO
    5
    WC5758 NSE M&MFIN
    6
    WC5758 NSE 20MICRONS
    25.823112
    7
    WC5758 NSE CONCOR
    8
    WC5758 NSE COALINDIA
    9
    WC5758 NSE BOSCHLTD
    10
    WC5758 NSE BERGEPAINT
    11
    WC5758 NSE 5PAISA
    40.795512
    12
    WC5758 NSE TATAELXSI
    13
    WC5758 NSE HINDPETRO
    14
    WC5758 NSE DISHTV
    Worksheet: ap-Sheet1
    ….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!!

  3. #153
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    In support of this Thread:
    http://www.excelfox.com/forum/showthread.php/2364-Delete-row
    http://www.excelfox.com/forum/showth...364-Delete-row


    _____ Workbook: BasketOrder..xlsx ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K L M N O P Q
    1 NSE EQ ACC NA NA NA 0 1 0 BUY MARKET NA CLI MIS DAY WC5758 NA
    2 NSE EQ ADANIPORTS NA NA NA 0 1 0 SELL MARKET NA CLI MIS DAY WC5758 NA
    3 NSE EQ AMBUJACEM NA NA NA 0 1 0 BUY MARKET NA CLI MIS DAY WC5758 NA
    4 NSE EQ ASIANPAINT NA NA NA 0 1 0 BUY MARKET NA CLI MIS DAY WC5758 NA
    5 NSE EQ AXISBANK NA NA NA 0 1 0 BUY MARKET NA CLI MIS DAY WC5758 NA
    6 NSE EQ BANKBARODA NA NA NA 0 1 0 SELL MARKET NA CLI MIS DAY WC5758 NA
    7
    Worksheet: BasketOrder. (1)


    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I
    1 Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    2 NSE ADANIPORTS EQ 409 409 398.65 407.2 402
    3 NSE ABC EQ 216.2 219.15 215.15 215.8 218
    4 NSE ASIANPAINT EQ 1409 1441.95 1401.85 1404.2 1441.3
    5 NSE AXISBANK EQ 732.9 739.3 728.15 727.45 733.65
    6 NSE BANKBARODA EQ 118.8 119.15 114.7 118.35 115.25
    7 NSE BHARTIARTL EQ 342.95 348.5 337.4 342.55 343.05
    8
    Worksheet: 1-Sheet1



    The Process:
    If cells of column C of basketorder.xlsx matches with cells of column B of 1.xlsx then delete the entire row of 1.xlsx(here entire row means the cells which matches delete that entire row)


    _____ Workbook: BasketOrder..xlsx ( Using Excel 2007 32 bit )
    NSE EQ ACC NA NA
    NSE EQ ADANIPORTS NA NA
    NSE EQ AMBUJACEM NA NA
    NSE EQ ASIANPAINT NA NA
    NSE EQ AXISBANK NA NA
    NSE EQ BANKBARODA NA NA
    Worksheet: BasketOrder. (1)

    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    NSE ADANIPORTS EQ 409 409 398.65 407.2 402
    NSE ABC EQ 216.2 219.15 215.15 215.8 218
    NSE ASIANPAINT EQ 1409 1441.95 1401.85 1404.2 1441.3
    NSE AXISBANK EQ 732.9 739.3 728.15 727.45 733.65
    NSE BANKBARODA EQ 118.8 119.15 114.7 118.35 115.25
    NSE BHARTIARTL EQ 342.95 348.5 337.4 342.55 343.05
    Worksheet: 1-Sheet1
    ….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!!

  4. #154
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Using data from last post

    Before=
    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    2
    NSE ADANIPORTS EQ
    409
    409
    398.65
    407.2
    402
    3
    NSE ABC EQ
    216.2
    219.15
    215.15
    215.8
    218
    4
    NSE ASIANPAINT EQ
    1409
    1441.95
    1401.85
    1404.2
    1441.3
    5
    NSE AXISBANK EQ
    732.9
    739.3
    728.15
    727.45
    733.65
    6
    NSE BANKBARODA EQ
    118.8
    119.15
    114.7
    118.35
    115.25
    7
    NSE BHARTIARTL EQ
    342.95
    348.5
    337.4
    342.55
    343.05
    8
    Worksheet: 1-Sheet1

    After=
    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    2
    NSE ABC EQ
    216.2
    219.15
    215.15
    215.8
    218
    3
    NSE BHARTIARTL EQ
    342.95
    348.5
    337.4
    342.55
    343.05
    4
    Worksheet: 1-Sheet1



    Code:
    '
    Sub Vixer7() ' http://www.excelfox.com/forum/showthread.php/2364-Delete-row
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook, Wb2 As Workbook ' (These will be set later when the workbooks are opened)
    Dim strWb1 As String: Let strWb1 = "1.xls"
    Dim strWb2 As String: Let strWb2 = "BasketOrder.xlsx" ' "BasketOrder..xlsx"
    '1b) Worksheets info
    Dim Ws1 As Worksheet, Ws2 As Worksheet ' (These will be set later when the workbooks are opened)
    Dim Lr1 As Long, Lr2 As Long: Let Lr1 = 7: Lr2 = 6 ' For sample file
    Rem 2 Open files   ..... we have to Open all the files all files are closed except the vba placed file
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\BasketOrder..xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb2
     Set Wb2 = ActiveWorkbook '
     Set Ws2 = Wb2.Worksheets.Item(1)
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\1.xls"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    Rem 3 The Process ..."....If cells of column C of basketorder.xlsx matches with cells of column B of 1.xlsx then delete the entire row of 1.xlsx...."....
    ' 3a) Range.Find Method  range info
    ' 3a)(i) Search range ( range to be searched )
    Dim rngSrch As Range: Set rngSrch = Ws2.Range("C1:C" & Lr2 & "") ' .."....column C of basketorder.xlsx
    ' 3a)(ii)' Data range, items to be searched for
    Dim rngDta As Range: Set rngDta = Ws1.Range("B2:B" & Lr1 & "") '  .."....cells of column B of 1.xlsx
    ' 3b) MAIN LOOP for all cells in basketorder.xlsx
    Dim Cnt As Long '_====================================MAIN LOOP===========================================
        For Cnt = Lr2 To 1 Step -1 ' data range to be searched for.... Important: I am going to delete rows in a loop: usually do such delete things in a backward loop. This is because I then effectively do a process on a cell or cells "behind me". So the process is done on a cell or cells no longer being considered. If I do the looping conventionally in the forward direction, then modification caused by the delete may effect the cells above, particularly their position. This can cause problems: After a delete, the cells above "move down". On the next loop I will then consider a cell above where I just was. So I will likely miss the next row to be considered, since that now occupies the position of the current loop. An alternative would be to loop forward, but after a delete to reduce the Loop count, Cnt, by 1. But changing the loop count variable in a loop is generally considered to be a bad idea     https://www.mrexcel.com/forum/excel-questions/803662-byte-backward-loop.html#post3929967
        Dim MtchedCel As Variant ' For the range object of a matched cell if found, if not found it will be  Nothing  , so we must use a variant to allow for the type of  Range  or  Nothing
         Set MtchedCel = rngSrch.Find(What:=rngDta.Item(Cnt), After:=rngSrch.Item(1), LookIn:=xlValues, Lookat:=xlWhole, Searchdirection:=xlNext, MatchCase:=True) ' rngDta.Item(Cnt) will be a cell of column C of basketorder.xlsx
            If Not MtchedCel Is Nothing Then ' If  cell of column C of basketorder.xlsx matches with cells of column B of 1.xlsx  Then .....
             rngDta.Rows(Cnt).EntireRow.Delete Shift:=xlUp ' ..... delete the entire row of 1.xlsx
            Else
            End If
            
        Next Cnt '_====================================MAIN LOOP===============================================
    Rem 4  ...."... after the process close and save the file so that changes should be saved
     Wb1.Close savechanges:=True
    End Sub
    Attached Files Attached Files

  5. #155
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    Making Lr dynamic ( using rng.End(XlUp) for a single column. )

    Extra notes in support of this Thread:
    http://www.excelfox.com/forum/showth...364-Delete-row
    http://www.excelfox.com/forum/showth...ll=1#post11463
    http://www.excelfox.com/forum/showthread.php/2364-Delete-row





    Making Lr dynamic
    ( using rng.End(XlUp) for a single column. )


    For example, from http://www.excelfox.com/forum/showth...364-Delete-row :
    BasketOrder.xlsx for column C, Lr is 6
    ( BasketOrder.xlsx : https://app.box.com/s/v4b19po7jtjmh7wcswykbij3y896dv05
    )
    _____ Workbook: BasketOrder.xlsx ( Using Excel 2007 32 bit )
    Row\Col B C D
    1 EQ ACC NA
    2 EQ ADANIPORTS NA
    3 EQ AMBUJACEM NA
    4 EQ ASIANPAINT NA
    5 EQ AXISBANK NA
    6 EQ BANKBARODA NA
    7
    Worksheet: BasketOrder. (1)

    Lr2, for column C is :
    Ws2.Range("C" & Ws2.Rows.Count).End(xlUp).Row
    or
    Ws2.Cells.Item(Ws2.Rows.Count, 3).End(xlUp).Row
    or
    Ws2.Cells.Item(Ws2.Rows.Count, "C").End(xlUp).Row


    To explain:
    '_- 1 :- Rows.Count Property of a worksheet
    Ws2.Range("C" & Ws2.Rows.Count)
    or
    Ws2.Cells.Item(Ws2.Rows.Count, 3)
    or
    Ws2.Cells.Item(Ws2.Rows.Count, "C")


    For Excel 2007 and higher versions ( .xlsx .xlsm ), this is 1048576 rows in a worksheet ( ImmediateWindow RowsCount XL 2007.JPG : https://imgur.com/NHHdylV )
    Ws2.Range("C" & 1048576)
    or
    Ws2.Cells.Item(1048576, 3)
    or
    Ws2.Cells.Item(1048576, "C")

    This is the last cell in column C:
    _____ Workbook: BasketOrder.xlsx ( Using Excel 2007 32 bit )
    Row\Col B C D
    1048574
    1048575
    1048576
    Worksheet: BasketOrder. (1)

    So we are at the bottom of the worksheet….

    '_- 2 :- .End(xlUp) Property action
    This is the same as keyboard keys _ Ctrl+UpArrow
    Ctrl + UpArrow.JPG : https://imgur.com/w5w8KxZ

    ….This action will take you back up to the next filled cell:
    _End(XlUp).JPG : https://imgur.com/JQJxc1s

    ….So we are at the last filled cell in column C

    '_- 3 :- .Row Property
    This will give you the row number of the cell
    _Row.JPG : https://imgur.com/bMpaBOv




    For example, from http://www.excelfox.com/forum/showth...364-Delete-row :
    1.xls for column B, Lr is 7
    ( 1.xls : https://app.box.com/s/beqlzzl3nwjff2ocyz4ox8twu5jnqd6e )
    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col A B C
    1 Exchange Symbol Series/Expiry
    2 NSE ADANIPORTS EQ
    3 NSE ABC EQ
    4 NSE ASIANPAINT EQ
    5 NSE AXISBANK EQ
    6 NSE BANKBARODA EQ
    7 NSE BHARTIARTL EQ
    8
    Worksheet: 1-Sheet1

    Lr1, for column B is :
    Ws1.Range("B" & Ws1.Rows.Count).End(xlUp).Row
    or
    Ws1.Cells.Item(Ws1.Rows.Count, 2).End(xlUp).Row
    or
    Ws1.Cells.Item(Ws1.Rows.Count, "B").End(xlUp).Row


    To explain:
    '_- 1 :- Rows.Count Property of a worksheet
    Ws1.Range("B" & Ws1.Rows.Count)
    or
    Ws1.Cells.Item(Ws1.Rows.Count, 2)
    or
    Ws1.Cells.Item(Ws1.Rows.Count, "B")


    For Excel 97 - 2003 ( .xls ), this is 65536 rows in a worksheet ( ImmediateWindow RowsCount XL 2003.JPG : https://imgur.com/iOmrf9n )
    Ws1.Range("B" & 65536 ))
    or
    Ws1.Cells.Item( 65536 , 2)
    or
    Ws1.Cells.Item( 65536 , "B")


    This is the last cell in column B:
    (Last Worksheet Row in XL 2003.JPG : https://imgur.com/iaEPoZG )
    Attachment 2401
    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col A B C
    65533
    65534
    65535
    65536
    Worksheet: 1-Sheet1

    So we are at the bottom of the worksheet …

    '_- 2 :- .End(xlUp) Property action
    This is the same as keyboard keys _ Ctrl+UpArrow
    Ctrl + UpArrow.JPG : https://imgur.com/w5w8KxZ
    Attachment 2402

    …This action will take you back up to the next filled cell:
    _End(XlUp) XL2003.JPG : https://imgur.com/JYPd95V
    Attachment 2403

    ….So we are at the last filled cell in column B

    '_- 3 :- .Row Property
    This will give you the row number of the cell
    _ Row.JPG : https://imgur.com/ZWCFvmr
    Attachment 2404





    Example Demo
    For uploaded files..
    BasketOrder.xlsx : https://app.box.com/s/v4b19po7jtjmh7wcswykbij3y896dv05
    1.xls : https://app.box.com/s/beqlzzl3nwjff2ocyz4ox8twu5jnqd6e

    run this macro
    Code:
    Sub Vixer8_MakingLrDynamic() ' http://www.excelfox.com/forum/showthread.php/2364-Delete-row?p=11463&viewfull=1#post11463
    '
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook, Wb2 As Workbook ' (These will be set later when the workbooks are opened)
    Dim strWb1 As String: Let strWb1 = "1.xls"                             '      --- 1.xls      :       https://app.box.com/s/beqlzzl3nwjff2ocyz4ox8twu5jnqd6e
    Dim strWb2 As String: Let strWb2 = "BasketOrder.xlsx" ' "BasketOrder..xlsx"   --- BasketOrder.xlsx : https://app.box.com/s/v4b19po7jtjmh7wcswykbij3y896dv05
    '1b) Worksheets info
    Dim Ws1 As Worksheet, Ws2 As Worksheet ' (These will be set later when the workbooks are opened)
    '                 Dim Lr1 As Long, Lr2 As Long ' To be determined from files                                                                            : Let Lr1 = 7: Lr2 = 6 ' For sample files
    Rem 2 Open files   ..... we have to Open all the files all files are closed except the vba placed file
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\BasketOrder..xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb2
     Set Wb2 = ActiveWorkbook '
     Set Ws2 = Wb2.Worksheets.Item(1)
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\1.xls"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    
    
    Rem 3 making Lr dynamic
    Dim Lr2 As Long
     Let Lr2 = Ws2.Range("C" & Ws2.Rows.Count).End(xlUp).Row
     Let Lr2 = Ws2.Cells.Item(Ws2.Rows.Count, 3).End(xlUp).Row
     Let Lr2 = Ws2.Cells.Item(Ws2.Rows.Count, "C").End(xlUp).Row
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("B" & Ws1.Rows.Count).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, 2).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, "B").End(xlUp).Row
    
    '3b) demo
     Ws2.Activate
     MsgBox prompt:="Lr in worksheet " & Ws2.Name & ", in workbook " & Wb2.Name & " is   " & Lr2 & vbCrLf & "(last row in worksheet is   " & Ws2.Rows.Count & ")"
     Ws1.Activate
     MsgBox prompt:="Lr in worksheet " & Ws1.Name & ", in workbook " & Wb1.Name & " is   " & Lr1 & vbCrLf & "(last row in worksheet is   " & Ws1.Rows.Count & ")"
    
    Rem 4 close files
    Wb2.Close: Wb1.Close
    End Sub







    Ref:
    https://www.excelforum.com/hello-int...ess-forum.html
    http://www.excelfox.com/forum/showth...ll=1#post10192
    http://www.excelfox.com/forum/showth...1466#post11466











    BasketOrder.xlsx : https://app.box.com/s/v4b19po7jtjmh7wcswykbij3y896dv05
    1.xls : https://app.box.com/s/beqlzzl3nwjff2ocyz4ox8twu5jnqd6e
    Attached Images Attached Images
    Attached Files Attached Files

  6. #156
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    in support of this Thread:
    http://www.excelfox.com/forum/showth...1472#post11472
    https://www.mrexcel.com/forum/excel-...ation-vba.html
    http://www.vbaexpress.com/forum/show...Formula-by-vba
    http://www.excelforum.com/excel-prog...on-by-vba.html





    _____ Workbook: 124.xlsb ( Using Excel 2007 32 bit )
    Row\Col A B C D E F
    1 Symbol LTP 1st row contains headers so ignore the first row
    2 ACC 1587.95 50 1333.878 Column D is the result that I need by vba
    3 ADANIPORTS 402 70 337.68 I don't want formulas I need only the result in column D
    4 AMBUJACEM 218 20 183.12
    5 ASIANPAINT 1441.3 10 1210.692
    6 AXISBANK 733.65 5 616.266
    7 BANKBARODA 115.25 7 96.81
    8 BHARTIARTL 343.05 8 288.162
    9 BOSCHLTD 15150 19 12726
    10 BPCL 359 350 301.56
    11
    12 Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2
    13 1333.878
    14
    Worksheet: Sheet1

    _____ Workbook: sample.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    E
    12
    Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2
    13
    =B2*(1.5/100)*56
    Worksheet: Sheet1




    Before
    _____ Workbook: 124.xlsb ( Using Excel 2007 32 bit )
    Row\Col A B C D
    2 ACC 1587.95 50
    3 ADANIPORTS 402 70
    4 AMBUJACEM 218 20
    5 ASIANPAINT 1441.3 10
    6 AXISBANK 733.65 5
    7 BANKBARODA 115.25 7
    8 BHARTIARTL 343.05 8
    9 BOSCHLTD 15150 19
    10 BPCL 359 350
    Worksheet: Sheet1

    After
    _____ Workbook: 124.xlsb ( Using Excel 2007 32 bit )
    Row\Col A B C D
    2 ACC 1587.95 50 1333.878
    3 ADANIPORTS 402 70 337.68
    4 AMBUJACEM 218 20 183.12
    5 ASIANPAINT 1441.3 10 1210.692
    6 AXISBANK 733.65 5 616.266
    7 BANKBARODA 115.25 7 96.81
    8 BHARTIARTL 343.05 8 288.162
    9 BOSCHLTD 15150 19 12726
    10 BPCL 359 350 301.56
    Worksheet: Sheet1
    Attached Files Attached Files

  7. #157
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    In support of this Thread:
    http://www.excelfox.com/forum/showthread.php/2369-Calculation-by-vba?p=11472&viewfull=1#post11472
    http://www.excelfox.com/forum/showth...ll=1#post11472


    Quote Originally Posted by sumanjjj View Post
    i have data upto 100 or 200 rows it can be more all it depends i have to do the same process till the end of the data
    So we need to make Lr dynamic, for example
    sample.xlsx
    _____ Workbook: sample.xlsx ( Using Excel 2007 32 bit )
    Row\Col A B C D
    1 Symbol LTP
    2 ACC 1587.95 50
    3 ADANIPORTS 402 70
    4 AMBUJACEM 218 20
    5 ASIANPAINT 1441.3 10
    6 AXISBANK 733.65 5
    7 BANKBARODA 115.25 7
    8 BHARTIARTL 343.05 8
    9 BOSCHLTD 15150 19
    10 BPCL 359 350
    11
    Worksheet: Sheet1



    Code:
    '
    Sub Vixer8b_MakingLrDynamic() ' http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474
    '
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' (This will be set later when the workbooks are opened)
    Dim strWb1 As String: Let strWb1 = "sample.xlsx"
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' (This will be set later when the workbooks are opened)
    '                 Dim Lr1 As Long, Lr2 As Long ' To be determined from files                                                                            : Let Lr1 = 7: Lr2 = 6 ' For sample files
    Rem 2 Open file   .....
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    
    
    Rem 3 making Lr dynamic
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, 3).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, "C").End(xlUp).Row
    
    '3b)(i) demo (i)
     Ws1.Activate
     MsgBox prompt:="Lr in worksheet " & Ws1.Name & ", in workbook " & Wb1.Name & " is   " & Lr1 & vbCrLf & "(last row in worksheet is   " & Ws1.Rows.Count & ")"
    
    '3b)(ii) demo (ii)
     Ws1.Range("C" & Ws1.Rows.Count).Select ' select last cell in column C
     Application.Wait (Now + TimeValue("0:00:03"))  '  VBA wait 3 seconds    https://docs.microsoft.com/de-de/office/vba/api/excel.application.wait
    
     ActiveCell.End(xlUp).Select            ' go back up to last used cell in column C
     Application.Wait (Now + TimeValue("0:00:06"))  '  VBA wait 6 seconds
    
    Rem 4 close file
     Wb1.Close
    End Sub


    Code:
    Rem 3 making Lr dynamic
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, 3).End(xlUp).Row
     Let Lr1 = Ws1.Cells.Item(Ws1.Rows.Count, "C").End(xlUp).Row

    To explain:-

    _ Rows.Count
    Ws1.Range("C" & Ws1.Rows.Count)
    Or
    Ws1.Cells.Item(Ws1.Rows.Count, 3)
    Or
    Ws1.Cells.Item(Ws1.Rows.Count, "C")


    We are in a .xlsx file, so Rows.Count is 1048576
    Ws1.Range("C" & 1048576)
    or
    Ws1.Cells.Item(1048576, 3)
    or
    Ws1.Cells.Item(1048576, "C")


    This is the last cell in column C:
    Last cell in Column C in worksheet Sheet1 in workbook sample xlsx.JPG : https://imgur.com/HH9UKki
    Attachment 2413
    _____ Workbook: sample.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    1048574
    1048575
    1048576
    Worksheet: Sheet1

    So we are at the bottom of the worksheet…..

    _ .End(XlUp) Property action
    This is the same as keyboard keys _ Ctrl+UpArrow
    Ctrl + UpArrow.JPG : https://imgur.com/w5w8KxZ
    Attachment 2402

    …This action will take you back up to the next filled cell:
    _End(XlUp) in column C from last cell in worksheet Sheet1 in workbook sample xlsx : https://imgur.com/fIDDbYB
    Attachment 2411

    …so we are at the last cell in column C that is filled with something

    _ .Row Property
    This will return the row number or the cell to which it is applied.
    _Row for current active cell.JPG : https://imgur.com/uKVAIgN
    Attachment 2412

  8. #158
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Some further notes and information for this Thread:
    http://www.excelfox.com/forum/showth...1476#post11476
    http://www.excelfox.com/forum/showth...ulation-by-vba
    https://www.mrexcel.com/forum/excel-...ation-vba.html
    http://www.vbaexpress.com/forum/show...Formula-by-vba
    https://www.excelforum.com/excel-pro...on-by-vba.html


    There are many different was to achieve the same…
    Some further notes on changes that can be made to Sub Vixer9a() from here: http://www.excelfox.com/forum/showth...ll=1#post11475




    b) Rng.Value = Rng.Value

    Excel VBA has been written such that applying .Value to a cell or cells has a similar effect to writing manually into a cell.

    So if you do this:
    Range("A1").Value = "X"
    , it will write
    X
    in the first cell.
    You will then see in the first cell this
    X

    If you do this:
    Range("A1").Value = " = 1"
    , it will write
    = 1
    in the first cell.
    But, you will see in the first cell just the Value:
    1

    To explain:
    The .Value Property of a range object , for example a single cell, is what we "see" in the cell. But if you apply .Value to a cell it will write into the cell as if you did it manually.

    So, in your code you can replace this: …_
    Code:
    '3(iii) I need only result in the cell no formulas
     Ws1.Range("D2:D" & Lr1 & "").Copy
     Ws1.Range("D2:D" & Lr1 & "").PasteSpecial Paste:=xlPasteValues
     Let Application.CutCopyMode = False
    _.. with this:
    Code:
    '3(iii) I need only result in the cell no formulas
     Let Ws1.Range("D2:D" & Lr1 & "").Value = Ws1.Range("D2:D" & Lr1 & "").Value

    Code:
    Sub Vixer9b() ' demo for   rng.Value = rng.Value
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    ' Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' This will be set later when the workbook is opened
    Dim MyPath As String: Let MyPath = "C:\Users\sk\Desktop" '  ".....The file will be located in C:\Users\sk\Desktop ....
    Dim strWb1 As String: Let strWb1 = "sample.xlsx" '                                                          " ....and file name is sample.xlsx
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' This will be set later when the workbook is opened)
    Dim Lr1 As Long '      Let Lr1 = 10 for sample file  , but we will determine it dynamically after opening the file
    Rem 2 Open file   "..... file is not opened so we have to open the file by vba
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1  '  ...both files are located in same place
    ' Workbooks.Open Filename:=MyPath & "\" & strWb1              '  ...file will be located in C:\Users\sk\Desktop
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    ' make Lr1 dynamic .... http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
    Rem 3 The Process ..."....
    '3(i) ....Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2.. formula will be added by me in the code, put that formula in
     Ws1.Range("D2").Value = "=B2*(1.5/100)*56"
    '3(ii) ....drag it
     Ws1.Range("D2").AutoFill Destination:=Ws1.Range("D2:D" & Lr1 & ""), Type:=xlFillDefault
    '3(iii) I need only result in the cell no formulas
     Let Ws1.Range("D2:D" & Lr1 & "").Value = Ws1.Range("D2:D" & Lr1 & "").Value
    Rem 4 save it and close it
     Wb1.Save
     Wb1.Close
    End Sub




    _c) Apply "fixed vector"** form across a range

    I can apply the formula in its "fixed vector"** form across a range. In other words I can apply the same formula in its fixed vector form across a range. Applying the same fixed vector formula across a range will make any referred to cells change the shown formula appropriately to apply to the different cells

    ** In simplified terms, "fixed vector", means notation without the $. So..
    A1 is "fixed vector"
    $A$1 is absolute referencing

    So we can replace this:
    Code:
    '3(i) ....Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2.. formula will be added by me in the code, put that formula in
     Ws1.Range("D2").Value = "=B2*(1.5/100)*56"
    '3(ii) ....drag it
     Ws1.Range("D2").AutoFill Destination:=Ws1.Range("D2:D" & Lr1 & ""), Type:=xlFillDefault
    With this:
    Code:
    '3(i)(ii) ....Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2..   ....drag it formula will be added by me in the code, put that formula in
     Ws1.Range("D2:D" & Lr1 & "").Value = "=B2*(1.5/100)*56"
    Code:
    Sub Vixer9c() ' demo for   fixed vector applied across a range
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    ' Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' This will be set later when the workbook is opened
    Dim MyPath As String: Let MyPath = "C:\Users\sk\Desktop" '  ".....The file will be located in C:\Users\sk\Desktop ....
    Dim strWb1 As String: Let strWb1 = "sample.xlsx" '                                                          " ....and file name is sample.xlsx
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' This will be set later when the workbook is opened)
    Dim Lr1 As Long '      Let Lr1 = 10 for sample file  , but we will determine it dynamically after opening the file
    Rem 2 Open file   "..... file is not opened so we have to open the file by vba
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1  '  ...both files are located in same place
    ' Workbooks.Open Filename:=MyPath & "\" & strWb1              '  ...file will be located in C:\Users\sk\Desktop
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    ' make Lr1 dynamic .... http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
    Rem 3 The Process ..."....
    '3(i)(ii) ....Multiply the value of B2 by 1.5%, then multiply that result by 56 and then paste the result in D2..   ....drag it formula will be added by me in the code, put that formula in
     Ws1.Range("D2:D" & Lr1 & "").Value = "=B2*(1.5/100)*56"
    '3(iii) I need only result in the cell no formulas
     Let Ws1.Range("D2:D" & Lr1 & "").Value = Ws1.Range("D2:D" & Lr1 & "").Value
    Rem 4 save it and close it
     Wb1.Save
     Wb1.Close
    End Sub





    _d) Internal calculation with VBA arrays
    We do not need to put formulas into any cells.
    We can do the calculations internally, within coding, and then paste all the values out in one go.
    Using VBA arrays is a convenient way to do this.

    _a) First we bring all the data into an array.
    _b) Then we do the calculations
    _c) Finally we paste out all the calculated values in one go

    We can replace all of Rem3 with new coding
    Rem 3 The Process .. using VBA arrays
    '3_a) First we bring all the data into an array.
    '3_b) Now we do the calculations
    '3_c) Finally we paste out all the calculated values in one go

    Code:
    Rem 3 The Process ...using VBA arrays
    '3_a) First we bring all the data into an array. (We also take in the column D values, even if the column D is empty)
    Dim arrDta() As Variant
     Let arrDta() = Ws1.Range("A1:D" & Lr1 & "").Value
    '3_b) Now we do the calculations looping through the row data held internally in the data array, arrDta()
    Dim Cnt As Long
        For Cnt = 2 To Lr1
         Let arrDta(Cnt, 4) = arrDta(Cnt, 2) * (1.5 / 100) * 56 ' .. like.. column "D" = column "B" * (1.5/100) * 56
        Next Cnt
    '3_c) Finally we paste out all the calculated values ( and also the original data )  in one go
     Ws1.Range("A1:D" & Lr1 & "").Value = arrDta()
    Code:
    Sub Vixer9d() ' demo using VBA arrays
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    ' Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' This will be set later when the workbook is opened
    Dim MyPath As String: Let MyPath = "C:\Users\sk\Desktop" '  ".....The file will be located in C:\Users\sk\Desktop ....
    Dim strWb1 As String: Let strWb1 = "sample.xlsx" '                                                          " ....and file name is sample.xlsx
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' This will be set later when the workbook is opened)
    Dim Lr1 As Long '      Let Lr1 = 10 for sample file  , but we will determine it dynamically after opening the file
    Rem 2 Open file   "..... file is not opened so we have to open the file by vba
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1  '  ...both files are located in same place
    ' Workbooks.Open Filename:=MyPath & "\" & strWb1              '  ...file will be located in C:\Users\sk\Desktop
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    ' make Lr1 dynamic .... http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
    Rem 3 The Process ...using VBA arrays
    '3_a) First we bring all the data into an array. (We also take in the column D values, even if the column D is empty)
    Dim arrDta() As Variant
     Let arrDta() = Ws1.Range("A1:D" & Lr1 & "").Value
    '3_b) Now we do the calculations looping through the row data held internally in the data array, arrDta()
    Dim Cnt As Long
        For Cnt = 2 To Lr1
         Let arrDta(Cnt, 4) = arrDta(Cnt, 2) * (1.5 / 100) * 56 ' .. like.. column "D" = column "B" * (1.5/100) * 56
        Next Cnt
    '3_c) Finally we paste out all the calculated values ( and also the original data )  in one go
     Ws1.Range("A1:D" & Lr1 & "").Value = arrDta()
    Rem 4 save it and close it
     Wb1.Save
     Wb1.Close
    End Sub




    _e) Evaluate Range
    see next post:

  9. #159
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10

    e) Evaluate Range

    _e) Evaluate Range

    It is possible to get array type calculations in Excel. Nobody fully understands this topic, and a lot of things are found by chance to work in a way such as to do array type calculations, or rather , array type results can be obtained.

    Evaluate Range techniques often allow a looping process to be replaced ba a single line of code. Broadly this arises due to two things:
    _1) Excel frequently updates all cells in a spreadsheet by going across the columns in a row , then down a row, then across the columns in the next row … etc.
    Usually a user "using" a single cell is like when it selected, and/ or the carriage Return key is used, and so it appears to us as if the cell is Updated and displayed at one time. There are various ways to display more than one cell in a single spreadsheet update.
    _2) In VBA there is an Evaluate Method ( https://docs.microsoft.com/en-us/off...ation.evaluate ). In simplified terms, this allows calculation within VBA as if the calculations were written and done in a spreadsheet.

    It is possible sometimes to get the Evaluate function to return an array representing the calculations across a range
    There is no clear documentation on any of the array type things discussed in this post, and it is often suggested that getting array results in any form in Excel has occurred by chance and no one understands fully what is going on.


    As an example, considering the last macro which looped to produce an array based on doing these calculations of this form, from down rows of 2 to Lr1
    B2*(1.5/100)*56
    B3*(1.5/100)*56
    B4*(1.5/100)*56

    _…. etc.

    We find that Rem 3 from the last macro, Sub Vixer9d() , can be replaced by
    Code:
    Rem 3 The Process ...   using Evaluate Range
     Ws1.Range("D2:D" & Lr1 & "").Value = Ws1.Evaluate("=" & Range("B2:B" & Lr1 & "").Address & "*(1.5/100)*56")

    The purpose of ("=" & Range("B2:B" & Lr1 & "") is to give us the formula form of like
    =B2:B10
    Hence the Range used does not need to be Qualified, such as by a worksheet, like in Ws1.Range
    ( There is an alternative form of Evaluate(" __ ") , which is often referred to as the "shorthand form" of Evaluate(" __ ") . It looks like this _ [ ___ ] _ . So you may now see what Mark L was suggesting here: https://www.excelforum.com/excel-pro...ml#post5190685 )

    It is , however , important to qualify Evaluate. this is because we want to do an evaluation as if the formula within Evaluate(" ___ ") , was in the cell in worksheet, Ws1. If we omit the qualifying _ Ws1. _ , before the Evaluate , then we may do an evaluation of the formula in a different worksheet.


    Code:
    Sub Vixer9e() ' demo  for  Evaluate Range
    Rem 1 Workbook and worksheets info
    '1a) Workbook info
    ' Dim Wbm As Workbook: Set Wbm = ThisWorkbook ' The workbook containing macro
    Dim Wb1 As Workbook ' This will be set later when the workbook is opened
    Dim MyPath As String: Let MyPath = "C:\Users\sk\Desktop" '  ".....The file will be located in C:\Users\sk\Desktop ....
    Dim strWb1 As String: Let strWb1 = "sample.xlsx" '                                                          " ....and file name is sample.xlsx
    '1b) Worksheets info
    Dim Ws1 As Worksheet ' This will be set later when the workbook is opened)
    Dim Lr1 As Long '      Let Lr1 = 10 for sample file  , but we will determine it dynamically after opening the file
    Rem 2 Open file   "..... file is not opened so we have to open the file by vba
    ' Workbooks.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\vixer\sample.xlsx"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & strWb1  '  ...both files are located in same place
    ' Workbooks.Open Filename:=MyPath & "\" & strWb1              '  ...file will be located in C:\Users\sk\Desktop
     Set Wb1 = ActiveWorkbook ' The workbook just opened will now be the current active workbook
     Set Ws1 = Wb1.Worksheets.Item(1)
    
    ' make Lr1 dynamic .... http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11474&viewfull=1#post11474
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count).End(xlUp).Row
    Rem 3 The Process ...   using Evaluate Range
     Ws1.Range("D2:D" & Lr1 & "").Value = Ws1.Evaluate("=" & Range("B2:B" & Lr1 & "").Address & "*(1.5/100)*56")
    Rem 4 save it and close it
     Wb1.Save
     Wb1.Close
    End Sub






    Using Evaluate often results in a much shorter coding.

    For example, taking Sub Vixer9e() , and making a few other simplifications we can come up with a much shorter coding.


    Code:
    Sub Vixer9f() ' simplified coding ( using Range Evaluate )
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "sample.xlsx"  '  ...both files are located in same place
    Rem 3 The Process ...   using Evaluate Range
     ActiveSheet.Range("D2:D" & ActiveSheet.Range("C" & ActiveSheet.Rows.Count).End(xlUp).Row & "").Value = ActiveSheet.Evaluate("=" & Range("B2:B" & ActiveSheet.Range("C" & ActiveSheet.Rows.Count).End(xlUp).Row & "").Address & "*(1.5/100)*56")
    Rem 4 save it and close it
     ActiveWorkbook.Close savechanges:=True
    End Sub





    I personally do not like such coding because
    _(i) They are more difficult to understand, especially at a later date,
    _(ii) They are less flexible for adjustment.
    _(iii) There may be some missing detail which might cause the coding to fail sometimes in certain circumstances
    Attached Files Attached Files

  10. #160
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    in support of this post:
    https://excel.tips.net/T001940_Hidin...ell_Value.html
    https://excel.tips.net/T001940_Hiding_Rows_Based_on_a_Cell_Value.html



    Hello Ryanne
    Rather than modifying the coding, it would probably be easier to use a simple "events" type coding which automatically kicks in when a range value is changed in a worksheet. Something of this form:.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
     Target.EntireRow.Hidden = True
    End Sub
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    '
    'End Sub
    This coding will need to be in a worksheet code module.
    Follow , for example these 6 steps to create such a coding:

    _1) Right click on the tab of the worksheet of interest
    _2) Select View Code
    Worksheet code module via View Code after right click on tab.JPG : : https://imgur.com/ZiOuRVT
    Attachment 2426

    _3) Select the left side drop down list
    _4) Select Worksheet
    Worksheet.JPG : https://imgur.com/tCwHKBo
    Attachment 2427

    _5) Select the right drop down list
    _6) Select Change
    Change.JPG : https://imgur.com/NkbNPsL
    Attachment 2428

    ( Delete or ' comment out any other coding, such as the Private Sub Worksheet_SelectionChange which may have appeared automatically at step 4 )



    You can now add your coding within the Private Sub Worksheet_Change


    ( Hit Alt+F11 to return to spreadsheet view )

    The coding will kick off automatically when you change any cell value. It will hide the entire row which contains the cell whose value you changed


    In the uploaded file , I have added the coding to the third worksheet code module

    Alan
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Replies: 114
    Last Post: 03-04-2024, 02:39 PM
  2. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  3. Replies: 11
    Last Post: 10-13-2013, 10:53 PM
  4. Replies: 7
    Last Post: 08-28-2013, 12:57 AM
  5. Declaring API Functions In 64 Bit
    By marreco in forum Excel Help
    Replies: 2
    Last Post: 02-11-2013, 03:18 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
  •