Page 1 of 8 123 ... LastLast
Results 1 to 10 of 75

Thread: vba Copy Paste Conditional to put remark 1 2 3 .. etc

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    vba Copy Paste Conditional to put remark 1 2 3 .. etc

    This post is a Moderator Post Copy…. ( link to post is https://excelfox.com/forum/showthread.php/2433-vba-Copy-Paste-Conditional-to-put-remark-1-2-3-etc#post12828 or https://tinyurl.com/y3c7lvlh
    https://excelfox.com/forum/showthrea...-etc#post12828

    Currently the OP, ( possible real name most of the time , Avinash Singh from Mumbai India ), appears to have many of his own accounts ( hundreds by his own admission to me privately ) . In addition he has temporary access to many other peoples accounts.
    It appears that his current “job” is to paste a question into a forum, and pass any macro given on to the person assigning him the task old posting the question.
    He will often duplicate cross post a question.
    Quite often the question is wrong and the macros and files do not match up or are full of mistakes )
    ( He may have his own career plans in parallel to this current job. That is likely also to be responsible for some of his many duplicate cross postings of similar questions )
    He has a very poor understanding of the English language, and has never been anywhere near Excel or Microsoft Office. If the assigning person is not happy with any returned macro, then he may use some of his many canned replies or even attempt some reply himself in the hope of it generating another macro, which he passes on to the person assigning him the job of posting the question…
    He barely understand , if at all, anything he posts himself in a question of the replies he makes himself
    _.... If the assigning person is not happy with any returned macro, then he may use some of his many canned replies or even attempt some reply himself in the hope of it generating another macro, which he passes on to the person assigning him the job of posting the question…
    He barely understand , if at all, anything he posts himself in a question of the replies he makes himself
    _..... If the assigning person is not happy with any returned macro, then he may use some of his many canned replies or even attempt some reply himself in the hope of it generating another macro, which he passes on to the person assigning him the job of posting the question…
    He barely understand , if at all, anything he posts himself in a question of the replies he makes himself
    _.... If the assigning person is not happy with any returned macro, then he may use some of his many canned replies or even attempt some reply himself in the hope of it generating another macro, which he passes on to the person assigning him the job of posting the question…
    He barely understand , if at all, anything he posts himself in a question of the replies he makes himself

    _... and so on, and so on…


    The questions are often variations on a similar one. In the next copy of the first Thread post, I am attempting to collect / merge / reference postings of those which can approximately be given the title of …
    vba Copy Paste Conditional to put remark 1 2 3 .. etc





    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg.9fsvd9zwZii9gMUka-NbIZ
    https://www.youtube.com/watch?v=jdPeMPT98QU
    https://www.youtube.com/watch?v=QdwDnUz96W0&lc=Ugx3syV3Bw6bxddVyBx4AaABAg
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=UgxsozCmRd3RAmIPO5B4AaABAg.9fxrOrrvTln9g9wr8mv2 CS
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=Ugw6zxOMtNCfmdllKQl4AaABAg
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=UgyT1lo2YMUyZ50bLeR4AaABAg.9fz3_oaiUeK9g96yGbAX 4t
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=Ugx5d-LrmoMM_hsJK2N4AaABAg.9fyL20jCtOI9g7pczEpcTz
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=UgyT1lo2YMUyZ50bLeR4AaABAg.9fz3_oaiUeK9g7lhoX-ar5
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=Ugx5d-LrmoMM_hsJK2N4AaABAg.9fyL20jCtOI9gD0AA-sfpl
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=Ugx5d-LrmoMM_hsJK2N4AaABAg.9fyL20jCtOI9gECpsAVGbh
    https://www.youtube.com/watch?v=U76ZRIzBhOA&lc=Ugw6zxOMtNCfmdllKQl4AaABAg.9g9wJCunNRa9gJGhDZ4R I2
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://eileenslounge.com/viewtopic.php?p=317218#p317218
    https://eileenslounge.com/viewtopic.php?p=316955#p316955
    https://eileenslounge.com/viewtopic.php?p=316955#p316955
    https://eileenslounge.com/viewtopic.php?p=316940#p316940
    https://eileenslounge.com/viewtopic.php?p=316927#p316927
    https://eileenslounge.com/viewtopic.php?p=317014#p317014
    https://eileenslounge.com/viewtopic.php?p=317006#p317006
    https://eileenslounge.com/viewtopic.php?p=316935#p316935
    https://eileenslounge.com/viewtopic.php?p=316875#p316875
    https://eileenslounge.com/viewtopic.php?p=316254#p316254
    https://eileenslounge.com/viewtopic.php?p=316280#p316280
    https://eileenslounge.com/viewtopic.php?p=315915#p315915
    https://eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315744#p315744
    https://www.eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315680#p315680
    https://eileenslounge.com/viewtopic.php?p=315743#p315743
    https://www.eileenslounge.com/viewtopic.php?p=315326#p315326
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40752
    https://eileenslounge.com/viewtopic.php?p=314950#p314950
    https://www.eileenslounge.com/viewtopic.php?p=314940#p314940
    https://www.eileenslounge.com/viewtopic.php?p=314926#p314926
    https://www.eileenslounge.com/viewtopic.php?p=314920#p314920
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 05-20-2024 at 03:48 PM.

  2. #2
    Hello

    Your data ?????
    SELL is K=1100.947 , sheet 2 column E is 1102 … so K is NOT > column E ---- so no output – no remark
    BUY is K = 130.734 , sheet 2 column E is 129 … so K is NOT < column E ----- so no output – no remark

    See here: http://www.excelfox.com/forum/showth...ll=1#post12837




    So Try this data : http://www.excelfox.com/forum/showth...ll=1#post12838



    ( You also need Function CL( ) )


    To explain the solution to you:
    If your data is
    _____ Workbook: Merge2.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    Symbol
    2
    ACC
    1
    2
    3
    3
    ADANIENT
    1
    4
    Worksheet: Sheet3

    arrS3() =
    arrS3(1) arrS3(2) arrS3(3)


    arrS3(1) =
    Symbol


    arrS3(2)=
    ACC
    1
    2
    3


    arrS3(3)=
    ADANIENT
    1


    Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) =


    File here: http://www.excelfox.com/forum/showth...ll=1#post12840
    (You also need Function CL( ) )



    Molly
    Last edited by Molly Brennholz; 03-20-2020 at 06:24 PM.

  3. #3
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Code:
    Option Explicit
    Sub STEP7() '
    Rem 1 Worksheets info
    Dim Wbm As Workbook, Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet
     Set Wbm = Workbooks.Open(ThisWorkbook.Path & "\Merge.xlsx")
     Set Ws1 = Wbm.Worksheets("Sheet1"): Set Ws2 = Wbm.Worksheets("Sheet2"): Set Ws3 = Wbm.Worksheets("Sheet3")
    Rem 2 data Input
    Dim arrS1() As Variant, arrS2() As Variant, arrS3() As Variant
     Let arrS1() = Ws1.Range("A1").CurrentRegion.Value: arrS2() = Ws2.Range("A1").CurrentRegion.Value
    '2b
     ReDim arrS3(1 To UBound(arrS1(), 1)) ' A 1 dimension array of arrays
    ''2b(i)
    ' Let arrS3(1) = Ws3.Range("A" & Ws3.Range("A1").CurrentRegion.Columns.Count & "") ' header row as a one dimensional array
    ''2b(ii) data rows array output
    
    Rem 3
    Dim cnt
        For cnt = 2 To UBound(arrS1(), 1) '  "row" count, cnt
        '2b)(ii)
        Dim Lc As Long: Let Lc = Ws3.Cells.Item(cnt, Ws3.Cells.Columns.Count).End(xlToLeft).Column ' last column in this row cnt
         Let arrS3(cnt) = Ws3.Range("A" & cnt & ":" & CL(Lc + 1) & cnt & "").Value ' - returns an array of 1 "row" into this element of the array of arrays
         Select Case arrS1(cnt, 9) ' column I
          Case "SELL" 'If column I is sell
            If arrS1(cnt, 11) > arrS2(cnt, 5) Then ' if column K is Greater than sheet2 of column E then
             Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
            Else
            End If
          Case "BUY"  'If column I is buy
           If arrS1(cnt, 11) < arrS2(cnt, 6) Then  ' if column K is lower than sheet2 of column F then
            Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
           Else
           End If
         End Select
        '3b) output "row"
         Let Ws3.Range("A" & cnt & "").Resize(1, Lc + 1).Value = arrS3(cnt)
        Next cnt
    Rem 4    ....and after putting the remark clear sheet 1 and sheet 2
     Ws1.Cells.ClearContents
     Ws2.Cells.ClearContents
    End Sub
    
    'If column I is sell
    'then see the value of column K &
    'if column K is Greater than sheet2 of column E then put the remark in sheet3 in the stock name from column B
    
    'If column I is buy
    'see the value of column K &
    'if column K is lower than sheet2 of column F then put the remark in sheet3 in the stock name from column B
    'remark will be in series like 1,2,3,4,5,6 and so on
    'vba is palced in a separate file
    'all files are located in same place
    'and after putting the remark clear sheet 1 and sheet 2
    '     http://www.excelfox.com/forum/showthread.php/1546-TESTING-Column-Letter-test-Sort
    Public Function CL(ByVal lclm As Long) As String '         http://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks-4.html#post4213980
        Do: Let CL = Chr(65 + (((lclm - 1) Mod 26))) & CL: Let lclm = (lclm - (1)) \ 26: Loop While lclm > 0
    End Function


    I used this code i have not found any error while raning the code sir but this code is not pasting the result sir plz relook sir

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg.A0opm95t2XEA0q3Kshmu uY
    https://www.youtube.com/watch?v=bRd4mJglWiM&lc=UgxRmh2gFhpmHNnPemR4AaABAg
    https://eileenslounge.com/viewtopic.php?p=318868#p318868
    https://eileenslounge.com/viewtopic.php?p=318311#p318311
    https://eileenslounge.com/viewtopic.php?p=318302#p318302
    https://eileenslounge.com/viewtopic.php?p=317704#p317704
    https://eileenslounge.com/viewtopic.php?p=317704#p317704
    https://eileenslounge.com/viewtopic.php?p=317857#p317857
    https://eileenslounge.com/viewtopic.php?p=317541#p317541
    https://eileenslounge.com/viewtopic.php?p=317520#p317520
    https://eileenslounge.com/viewtopic.php?p=317510#p317510
    https://eileenslounge.com/viewtopic.php?p=317547#p317547
    https://eileenslounge.com/viewtopic.php?p=317573#p317573
    https://eileenslounge.com/viewtopic.php?p=317574#p317574
    https://eileenslounge.com/viewtopic.php?p=317582#p317582
    https://eileenslounge.com/viewtopic.php?p=317583#p317583
    https://eileenslounge.com/viewtopic.php?p=317605#p317605
    https://eileenslounge.com/viewtopic.php?p=316935#p316935
    https://eileenslounge.com/viewtopic.php?p=317030#p317030
    https://eileenslounge.com/viewtopic.php?p=317030#p317030
    https://eileenslounge.com/viewtopic.php?p=317014#p317014
    https://eileenslounge.com/viewtopic.php?p=316940#p316940
    https://eileenslounge.com/viewtopic.php?p=316927#p316927
    https://eileenslounge.com/viewtopic.php?p=316875#p316875
    https://eileenslounge.com/viewtopic.php?p=316704#p316704
    https://eileenslounge.com/viewtopic.php?p=316412#p316412
    https://eileenslounge.com/viewtopic.php?p=316412#p316412
    https://eileenslounge.com/viewtopic.php?p=316254#p316254
    https://eileenslounge.com/viewtopic.php?p=316046#p316046
    https://eileenslounge.com/viewtopic.php?p=317050&sid=d7e077e50e904a138c794e1f2115da95#p317050
    https://www.youtube.com/@alanelston2330
    https://www.youtube.com/watch?v=yXaYszT11CA&lc=UgxEjo0Di9-9cnl8UnZ4AaABAg.9XYLEH1OwDIA35HNIei0z-
    https://eileenslounge.com/viewtopic.php?p=316154#p316154
    https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg
    https://teylyn.com/2017/03/21/dollarsigns/#comment-191
    https://eileenslounge.com/viewtopic.php?p=317050#p317050
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-28-2024 at 02:11 PM.

  4. #4
    Quote Originally Posted by Molly Brennholz View Post
    Hello

    Your data ?????
    SELL is K=1100.947 , sheet 2 column E is 1102 … so K is NOT > column E ---- so no output – no remark
    BUY is K = 130.734 , sheet 2 column E is 129 … so K is NOT < column E ----- so no output – no remark

    See here: http://www.excelfox.com/forum/showth...ll=1#post12837 ....
    Quote Originally Posted by fixer View Post
    ...I used this code i have not found any error while raning the code sir but this code is not pasting the result ..
    Correct. This is as expected. This is what you asked for
    no output – no remark = code is not pasting the result = There is no result to paste.

    Correct.

    Check your data. Check your logic. Explain again what should happen.
    Maybe you gave wrong data. Maybe you gave wrong logic.
    maybe you asked wromng question.
    Or i do not understand what you want.
    Try to explain again with more examples
    Last edited by Molly Brennholz; 03-20-2020 at 06:49 PM.

  5. #5
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Code:
    Option Explicit
    Sub STEP7() '
    Rem 1 Worksheets info
    Dim Wbm As Workbook, Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet
     Set Wbm = Workbooks.Open(ThisWorkbook.Path & "\Merge.xlsx")
     Set Ws1 = Wbm.Worksheets("Sheet1"): Set Ws2 = Wbm.Worksheets("Sheet2"): Set Ws3 = Wbm.Worksheets("Sheet3")
    Rem 2 data Input
    Dim arrS1() As Variant, arrS2() As Variant, arrS3() As Variant
     Let arrS1() = Ws1.Range("A1").CurrentRegion.Value: arrS2() = Ws2.Range("A1").CurrentRegion.Value
    '2b
     ReDim arrS3(1 To UBound(arrS1(), 1)) ' A 1 dimension array of arrays
    ''2b(i)
    ' Let arrS3(1) = Ws3.Range("A" & Ws3.Range("A1").CurrentRegion.Columns.Count & "") ' header row as a one dimensional array
    ''2b(ii) data rows array output
    
    Rem 3
    Dim cnt
        For cnt = 2 To UBound(arrS1(), 1) '  "row" count, cnt
        '2b)(ii)
        Dim Lc As Long: Let Lc = Ws3.Cells.Item(cnt, Ws3.Cells.Columns.Count).End(xlToLeft).Column ' last column in this row cnt
         Let arrS3(cnt) = Ws3.Range("A" & cnt & ":" & CL(Lc + 1) & cnt & "").Value ' - returns an array of 1 "row" into this element of the array of arrays
         Select Case arrS1(cnt, 9) ' column I
          Case "SELL" 'If column I is sell
            If arrS1(cnt, 11) > arrS2(cnt, 5) Then ' if column K is Greater than sheet2 of column E then
             
            Else
            Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
            End If
          Case "BUY"  'If column I is buy
           If arrS1(cnt, 11) < arrS2(cnt, 6) Then  ' if column K is lower than sheet2 of column F then
            
           Else
           Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
           End If
         End Select
        '3b) output "row"
         Let Ws3.Range("A" & cnt & "").Resize(1, Lc + 1).Value = arrS3(cnt)
        Next cnt
    Rem 4    ....and after putting the remark clear sheet 1 and sheet 2
     Ws1.Cells.ClearContents
     Ws2.Cells.ClearContents
     Wbm.Save
     Wbm.Close
     
    End Sub
    
    'If column I is sell
    'then see the value of column K &
    'if column K is Greater than sheet2 of column E then put the remark in sheet3 in the stock name from column B
    
    'If column I is buy
    'see the value of column K &
    'if column K is lower than sheet2 of column F then put the remark in sheet3 in the stock name from column B
    'remark will be in series like 1,2,3,4,5,6 and so on
    'vba is palced in a separate file
    'all files are located in same place
    'and after putting the remark clear sheet 1 and sheet 2
    
    Public Function CL(ByVal lclm As Long) As String '         http://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks-4.html#post4213980
        Do: Let CL = Chr(65 + (((lclm - 1) Mod 26))) & CL: Let lclm = (lclm - (1)) \ 26: Loop While lclm > 0
    End Function

    Thnx for the hint sir actually u misunderstood the condition i corrected the same sir
    but one issue is there
    i ran the code and i send the screenshot of that result plz see the attachment (result.png )
    and again i will ran the code and what i need if again the condition met then i need result but it will be in column C and if i again ran the code then it will be in column D
    and the number will be in series in column B it will be 1 and if it is column C then 2 and if column D then 3 and so on
    Attached Images Attached Images
    Last edited by fixer; 03-20-2020 at 08:50 PM.

  6. #6
    Sorry, I am having difficulty to understand you.
    I do not understand what you are saying.

    Upload a file and try again to explain.

  7. #7
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,452
    Rep Power
    10
    Problem is possibly your understanding of English language.

    __ < is less than
    __ > is greater than




    If arrS1(cnt, 11) > arrS2(cnt, 5) Then ----- If column K is Greater than column E Then
    If arrS1(cnt, 11) < arrS2(cnt, 5) Then ----- If column K is less than column E Then




    3 is greater than 2
    2 is less than 3
    3 is > 2
    2 is < 3

    3 > 2 is True
    3 > 5 is False
    2 < 1 is False
    3 > 5 is False




    Code:
          Case "SELL" 'If column I is sell
            If arrS1(Cnt, 11) > arrS2(Cnt, 5) Then ' if column K is Greater than sheet2 of column E then
            ' if column K is Greater than sheet2 of column E then do nothing
            Else
            ' if column K is less than or = to sheet2 of column E then
            Let arrS3(Cnt)(1, UBound(arrS3(Cnt), 2)) = UBound(arrS3(Cnt), 2) - 1 ' Put in a value in last array "column"
            End If
          Case "BUY"  'If column I is buy
           If arrS1(Cnt, 11) < arrS2(Cnt, 6) Then  ' if column K is lower than sheet2 of column F then
           ' if column K is lower than sheet2 of column E then do nothing
           Else
           '  if column K is greater than or = to sheet2 of column E then
           Let arrS3(Cnt)(1, UBound(arrS3(Cnt), 2)) = UBound(arrS3(Cnt), 2) - 1 ' Put in a value in last array "column"
           End If
    



    Molly did understand correct!!

    Vixer, You did explain it wrong!!

    Molly, you did it correct. Vixer explained it wrong. ( He has difficulty with English language )




    This is wrong:
    Quote Originally Posted by fixer View Post
    If column I is sell then see the value of column K & if column K is Greater than sheet2 of column E then put the remark in sheet3 in the stock name from column B
    This is correct:
    If column I is sell then see the value of column K & if column K is less than sheet2 of column E then put the remark in sheet3 in the stock name from column B
    Last edited by DocAElstein; 03-20-2020 at 10:11 PM.
    ….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!!

  8. #8
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Plz see the sample file doc sir
    Attached Files Attached Files

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

    What is the problem??

    You want this…Suppose column B already has data
    and after that I am runing the macro
    then the result will be pasted to column C
    and the result which we have to paste is 2
    and again when I ran the macro then column C can have the data or it cant have
    but if column C has data then the result should be paste as 3 and so on….


    Have you tried Molly’s macro ??

    I have tried Molly’s macro . ( your version here: http://www.excelfox.com/forum/showth...ll=1#post12846 ) it does this:

    Start like this
    _____ Workbook: Merge (1).xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    Symbol
    2
    ACC
    3
    ADANIENT
    4
    Worksheet: Sheet3


    Now Run it once … It does this

    _____ Workbook: Merge (1).xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    Symbol
    2
    ACC
    1
    3
    ADANIENT
    1
    4
    Worksheet: Sheet3

    Now run it again… It does this

    _____ Workbook: Merge (1).xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    Symbol
    2
    ACC
    1
    2
    3
    ADANIENT
    1
    2
    4
    Worksheet: Sheet3

    Now run it again… It does this..

    _____ Workbook: Merge (1).xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    1
    Symbol
    2
    ACC
    1
    2
    3
    3
    ADANIENT
    1
    2
    3
    4
    Worksheet: Sheet3

    and so on.............................

    So it does exactly what you asked for

    What is your problem ???


    The macro from Molly is doing exactly what you are asking for !!!!




    Code:
    Sub STEP7_() '
    Rem 1 Worksheets info
    Dim Wbm As Workbook, Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet
     Set Wbm = Workbooks("Merge (1).xlsx")
    ' Set Wbm = Workbooks.Open(ThisWorkbook.Path & "\Merge1.xlsx")  '   "\Merge.xlsx") '  change to suit
     Set Ws1 = Wbm.Worksheets("Sheet1"): Set Ws2 = Wbm.Worksheets("Sheet2"): Set Ws3 = Wbm.Worksheets("Sheet3")
    Rem 2 data Input
    Dim arrS1() As Variant, arrS2() As Variant, arrS3() As Variant
     Let arrS1() = Ws1.Range("A1").CurrentRegion.Value: arrS2() = Ws2.Range("A1").CurrentRegion.Value
    '2b
     ReDim arrS3(1 To UBound(arrS1(), 1)) ' A 1 dimension array of arrays
    ''2b(i)
    ' Let arrS3(1) = Ws3.Range("A" & Ws3.Range("A1").CurrentRegion.Columns.Count & "") ' header row as a one dimensional array
    ''2b(ii) data rows array output
    
    Rem 3
    Dim cnt
        For cnt = 2 To UBound(arrS1(), 1) '  "row" count, cnt
        '2b)(ii)
        Dim Lc As Long: Let Lc = Ws3.Cells.Item(cnt, Ws3.Cells.Columns.Count).End(xlToLeft).Column ' last column in this row cnt
         Let arrS3(cnt) = Ws3.Range("A" & cnt & ":" & CL(Lc + 1) & cnt & "").Value ' - returns an array of 1 "row" into this element of the array of arrays
         Select Case arrS1(cnt, 9) ' column I
          Case "SELL" 'If column I is sell
            If arrS1(cnt, 11) > arrS2(cnt, 5) Then ' if column K is Greater than sheet2 of column E then
            ' do nothing
            Else
            Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
            End If
          Case "BUY"  'If column I is buy
           If arrS1(cnt, 11) < arrS2(cnt, 6) Then  ' if column K is lower than sheet2 of column F then
           ' do nothing
           Else
           Let arrS3(cnt)(1, UBound(arrS3(cnt), 2)) = UBound(arrS3(cnt), 2) - 1 ' Put in a value in last array "column"
           End If
         End Select
        '3b) output "row"
         Let Ws3.Range("A" & cnt & "").Resize(1, Lc + 1).Value = arrS3(cnt)
        Next cnt
    Rem 4    ....and after putting the remark clear sheet 1 and sheet 2
    ' Ws1.Cells.ClearContents
    ' Ws2.Cells.ClearContents
    ' Wbm.Save
    ' Wbm.Close
     
    End Sub
    
    
    Public Function CL(ByVal lclm As Long) As String '         http://www.excelforum.com/development-testing-forum/1101544-thread-post-appendix-no-reply-needed-please-do-not-delete-thanks-4.html#post4213980
        Do: Let CL = Chr(65 + (((lclm - 1) Mod 26))) & CL: Let lclm = (lclm - (1)) \ 26: Loop While lclm > 0
    End Function
    Last edited by DocAElstein; 03-21-2020 at 02:02 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!!

  10. #10
    Thanks, Alam, for the confirmation
    Molly
    x

Similar Threads

  1. Replies: 26
    Last Post: 09-26-2020, 05:56 PM
  2. VBA -- Copy/Paste across sheets
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 09-21-2012, 02:07 PM

Tags for this Thread

Posting Permissions

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