Export file Modification in Code

Adeel1

New Member
Joined
Sep 29, 2019
Messages
21
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Below code is working well there is no issue I want some modification in it,

In Col C against cust id if any alphabet D exist in col M that number in col E will be exported in file with below code with below condition
1>> if col L has 500 then code will be 20617 if col L has 1500 then code will be 15156 as per table col N and O in exported file.
2>> in col L there is 6000 in L3 but there is no 6000 in table of N and O then code will repeat that numbers two times with codes 20670,20667 (4000+2000) or 20669,20667,15142 (3000+2000+1000) also for rest if isn’t exist,
In real table isn’t exist in sheet or in file these codes will be in macro

All others thing will remain same


Thnx in advance

VBA Code:
Sub ExportData()
    Dim wshS As Worksheet
    Dim s As Long
    Dim m As Long
    Dim wbkT As Workbook
    Dim wshT As Worksheet
    Dim t As Long
    Dim id As Variant

    Application.ScreenUpdating = False
    Set wshS = ThisWorkbook.Worksheets("sheet3")
    m = wshS.Range("A" & wshS.rows.Count).End(xlUp).Row
    Set wbkT = Workbooks.Add(xlWBATWorksheet)
    Set wshT = wbkT.Worksheets(1)
    wshT.Name = "SECH"
    wshT.Range("A1:D1").Value = Array("SUBNO", "EQUIPID", "ACTION", "STATUS")
    t = 1
    For s = 2 To m
        If IsNumeric(Application.Match(wshS.Range("c" & s).Value, Array(1160568), 0)) Then
            For Each id In Array(15326, 37217, 37467, 15436)
                t = t + 1
                wshT.Range("A" & t & ":D" & t).Value = _
                    Array(wshS.Range("e" & s).Value, id, "INST", "N")
            Next id
        ElseIf IsNumeric(Application.Match(wshS.Range("g" & s).Value, Array(31979), 0)) Then
            For Each id In Array(36467)
                t = t + 1
                wshT.Range("A" & t & ":D" & t).Value = _
                    Array(wshS.Range("e" & s).Value, id, "INST", "N")
            Next id
        ElseIf IsNumeric(Application.Match(wshS.Range("c" & s).Value, Array(8894941), 0)) Then
            ' These are not export
        Else
            For Each id In Array(15436, 15326)
                t = t + 1
                wshT.Range("A" & t & ":D" & t).Value = _
                    Array(wshS.Range("e" & s).Value, id, "INST", "N")
            Next id
        End If
    Next s

    wshT.Range("A1:D1").EntireColumn.AutoFit
    wbkT.CheckCompatibility = False
    wbkT.RemovePersonalInformation = True
    wbkT.SaveAs "C:\Users\adeel\Desktop\AA\SECH.xls", FileFormat:=xlExcel8
    wbkT.Close
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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