Results 1 to 10 of 41

Thread: copy,paste,calculate Cell value based on calculations & comparisonsother cells same row. Decimal places

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
    Hi
    Your macro is very good.
    You have written good coding.
    It is almost perfect.


    There is just one very small problem. It is just because VBA is confused when quotes are inside quotes. VBA does not like to see quotes inside other quotes. It get confused.

    If VBA see this: …_
    Code:
        "     "     "
    _.. VBA does not know what it is. VBA thinks maybe it is either this
    Code:
        "     "     "
    or this
    Code:
        "     "     "
    VBA does not like to see inside quotes 1 quote or 3 quotes or 5 quotes … etc

    VBA must always see 2 quotes "" ( or 4 quotes m"""", or 6 quotes """""" )etc..
    We must do a trick , like this
    Code:
        "     ""    "
    Or this:
    Code:
        "     ""    ""    "
    If you do this trick, then VBA will see for "" just one quote.

    So in your macro , like this is the problem: "________"_D is equal to H_"____"
    Code:
    "=IF(H2>D2,1/100*H2,IF(H2"D is equal to H"))"
    We must do trick: "________""_D is equal to H_""____"
    Code:
    "=IF(H2>D2,1/100*H2,IF(H2""D is equal to H""))"


    So in your macro,
    change the single quotes inside the outermost enclosing quotes to double quotes
    like this:
    ______________Ws1.Range(" 2: " & Lr1 & "").Value =__"__________""_D is equal to H_""____"
    Code:
    Sub STEP8()
      Dim Wb1 As Workbook, Ws1 As Worksheet, Lr1 As Long
      Set Wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\1.xls")
      Set Ws1 = Wb1.Worksheets.Item(1)
      Let Lr1 = Ws1.Range("H" & Ws1.Rows.Count).End(xlUp).Row
       Ws1.Range("J2:J" & Lr1 & "").Value = "=IF(H2>D2,1/100*H2,IF(H2""D is equal to H""))"
       Ws1.Range("J2:J" & Lr1 & "").Value = Ws1.Range("J2:J" & Lr1 & "").Value
       Ws1.Range("K2:K" & Lr1 & "").Value = "=IF(H2>D2,H2-J2,IF(H2""D is equal to H""))"
       Ws1.Range("K2:K" & Lr1 & "").Value = Ws1.Range("K2:K" & Lr1 & "").Value
       Wb1.Save
       Wb1.Close
    End Sub

    You did almost perfect in your macro. It was very close.

    Alan





    http://www.eileenslounge.com/viewtopic.php?f=30&t=34670
    Last edited by DocAElstein; 06-15-2020 at 05:25 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!!

Similar Threads

  1. Replies: 26
    Last Post: 09-26-2020, 05:56 PM
  2. Replies: 6
    Last Post: 08-28-2019, 09:42 AM
  3. copy data and paste it in another sheet
    By newbie2 in forum Excel Help
    Replies: 1
    Last Post: 07-15-2015, 01:38 PM
  4. Trapping Copy To Range Before Copy/Cut Paste
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 04-07-2011, 07:48 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
  •