ananya11

New Member
Joined
Feb 1, 2018
Messages
6
HI all,

I am using one macro file with below code . it`s perfectly file but now I need add one condition in same macro file .

New condition is : if in my Raw data worksheet column E having some specific model like C400,n9000,q10000 .
than calculation method id different ,

example file enclosed SD worksheet is the required result sheet .





VBA code is :
Code:
Sub MyMacro()
Dim intCount As Integer
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lngTRow, lngRow As Long
Set ws1 = Sheets("Raw Data")
Set ws2 = Sheets("SD")
 
'TargetDataRow
lngTRow = 8
ws1.Range("A1:B5").Copy
ws2.Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws2.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
  
ws2.Range("A7:E7") = Array("Customer Name", "S ID", "Device ID", "Counter", "Date")
  
For lngRow = 8 To ws1.Cells(Rows.Count, "A").End(xlUp).Row
If Not ws1.Range("G" & lngRow).Value = "N/A" Then
  ws2.Range("A" & lngTRow).Value = ws1.Range("A" & lngRow).Value
  ws2.Range("B" & lngTRow).Value = ws1.Range("C" & lngRow).Value
  ws2.Range("E" & lngTRow).Value = ws1.Range("G" & lngRow).Value
  ws2.Range("E" & lngTRow).NumberFormat = "dd-mm-yy"
  For intCount = 1 To 8
    ws2.Range("A" & lngTRow + intCount).Value = ws2.Range("A" & lngTRow).Value
    ws2.Range("B" & lngTRow + intCount).Value = ws2.Range("B" & lngTRow).Value
    ws2.Range("E" & lngTRow + intCount).Value = ws2.Range("E" & lngTRow).Value
    ws2.Range("E" & lngTRow + intCount).NumberFormat = "dd-mm-yy"
  Next intCount
  ws2.Range("D" & lngTRow).Resize(7) = Application.Transpose(ws1.Range("H" & _
    lngRow).Resize(, 7).Value)
  For intCount = 0 To 4
    If ws2.Range("D" & lngTRow + intCount).Text = "N/A" Then
    ws2.Range("D" & lngTRow + intCount).Value = 0
    End If
  Next intCount
  ws2.Range("D" & lngTRow + 7).FormulaR1C1 = "=SUM(R[-6]C:R[-5]C)"
  ws2.Range("D" & lngTRow + 8).FormulaR1C1 = "=SUM(R[-4]C:R[-5]C)"
  ws2.Range("C" & lngTRow) = ws1.Range("D" & lngRow)
  ws2.Range("C" & lngTRow + 1) = ws1.Range("D" & lngRow) & "-DA3"
  ws2.Range("C" & lngTRow + 2) = ws1.Range("D" & lngRow) & "-DA4"
  ws2.Range("C" & lngTRow + 3) = ws1.Range("D" & lngRow) & "-NC3"
  ws2.Range("C" & lngTRow + 4) = ws1.Range("D" & lngRow) & "-NC4"
  ws2.Range("C" & lngTRow + 5) = ws1.Range("D" & lngRow) & "-MC"
  ws2.Range("C" & lngTRow + 6) = ws1.Range("D" & lngRow) & "-BC"
  ws2.Range("C" & lngTRow + 7) = ws1.Range("D" & lngRow) & "-B"
  ws2.Range("C" & lngTRow + 8) = ws1.Range("D" & lngRow) & "-C"
lngTRow = lngTRow + 9
End If
Next
End Sub
 
Last edited by a moderator:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
For instance:
Code:
For lngRow = 8 To ws1.Cells(Rows.Count, "A").End(xlUp).Row
If Not ws1.Range("G" & lngRow).Value = "N/A" Then
    Select Case UCase(ws1.Range("E" & lngRow))
        Case "C400"
            'Code here
        Case "N9000"
            'Code here
        Case "Q10000"
            'Code here
    End Select
    End If
Next
 
Upvote 0
HI Thanks for Reply ,

This is data in my raw Sheet .

I need in my Raw data worksheet column E having some specific model like C400,n9000,q10000 .
than calculation method id different ,

Method is DA3-BC= DA3
NC3-MC=NC3


adasdsadaasd
sdsdsdsd
dsfsdf
dsf954
afdsdsf
TOTALDA3DA4NC3NC4MCBC
Customer NameIDS IDDevice IDP NameInstallation Date (dd-mm-yyyy)Date and Time Last Received111213112113172173
abc1323as239876as239876asdertfgyu C123 liffdgg02-24-201709-21-2017 02:01 PM31537208218761385613723182640
xyz4343uy567987uy567987asdertfgyu C400 liffdgg09-16-201409-21-2017 11:30 AM31537208218761385613723182640

<tbody>
</tbody><colgroup><col><col><col><col><col><col><col><col span="7"></colgroup>
 
Upvote 0
HI

And After Running Macro code Result Sheet SD like

adasdsadaasd
sdsdsdsd
dsfsdf
dsf954
afdsdsf
Customer NameS IDDevice IDCounterDate
abcas239876as2398763153721-09-17
abcas239876as239876-DA3208221-09-17
abcas239876as239876-DA4187621-09-17
abcas239876as239876-NC31385621-09-17
abcas239876as239876-NC41372321-09-17
abcas239876as239876-MC182621-09-17
abcas239876as239876-BC4021-09-17
abcas239876as239876-B395821-09-17
abcas239876as239876-C2757921-09-17
xyzuy567987uy5679873153721-09-17
xyzuy567987uy567987-DA3204221-09-17
xyzuy567987uy567987-DA4187621-09-17
xyzuy567987uy567987-NC31203021-09-17
xyzuy567987uy567987-NC41372321-09-17
xyzuy567987uy567987-MC182621-09-17
xyzuy567987uy567987-BC4021-09-17
xyzuy567987uy567987-B391821-09-17
xyzuy567987uy567987-C2575321-09-17

<tbody>
</tbody><colgroup><col><col><col><col><col></colgroup>


Thanks

Anu
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top