• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

help for macro formula not to appear in cells

RAM72

Member
Need help to make formula not to appear in cells

Actually with actual macro formula is appearing



Code:
Sub RAM()
Dim LastR As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("data")
Set ws2 = Sheets("summary")

LastR = ws1.Cells(Rows.Count, 1).End(xlUp).Row

ws2.Range("A1:E1").Value = ws1.Range("A1:E1").Value
ws2.Range(ws2.Range("A2"), ws2.Cells(LastR, 4)).Value = ws1.Range(ws1.Range("A2"), ws1.Cells(LastR, 4)).Value
ws2.Range(ws2.Range("A2"), ws2.Cells(LastR, 4)).RemoveDuplicates Columns:=Array(1, 2, 3, 4), Header:=xlNo
ws2.Range(ws2.Range("E2"), ws2.Cells(ws2.Cells(Rows.Count, 1).End(xlUp).Row, 5)).Value = _
"=SUMIFS(data!C,data!C[-4],RC[-4],data!C[-3],RC[-3],data!C[-2],RC[-2],data!C[-1],RC[-1])"

End Sub
 
Check this.


Code:
Sub RAM()
Dim LastR As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("data")
Set ws2 = Sheets("summary")

LastR = ws1.Cells(Rows.Count, 1).End(xlUp).Row

With ws2
    .Range("A1:E1").Value = ws1.Range("A1:E1").Value
    .Range(.Range("A2"), .Cells(LastR, 4)).Value = ws1.Range(ws1.Range("A2"), ws1.Cells(LastR, 4)).Value
    .Range(.Range("A2"), .Cells(LastR, 4)).RemoveDuplicates Columns:=Array(1, 2, 3, 4), Header:=xlNo
   
    .Range(.Range("E2"), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 5)).Value = _
    "=SUMIFS(data!C,data!C[-4],RC[-4],data!C[-3],RC[-3],data!C[-2],RC[-2],data!C[-1],RC[-1])"
    'or
    '.Range(.Range("E2"), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 5)) = _
    "=SUMIFS(data!E:E,data!A:A,A2,data!B:B,B2,data!C:C,C2,data!D:D,D2)"
   
    'convert to value
    .Range(.Range("E2"), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 5)).Value = _
    .Range(.Range("E2"), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 5)).Value
   
End With


End Sub
 
Back
Top