Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help i dont know why is my vba code not working Sub Delivery_Schedule_XML() 'turn off screen updating to avoid flicker effect of copy/paste On

Please help i dont know why is my vba code not working

Sub Delivery_Schedule_XML()

'turn off screen updating to avoid flicker effect of copy/paste On Error GoTo errHandler Application.ScreenUpdating = False

Dim current As Range Dim date_stamp As String Dim i, j As Integer Dim save_path As String Dim savename As String

date_stamp = Format(Date, "mm-dd-yyyy") 'save_path = "C:\Users\mmoschet\Desktop\Tariff Automation\LTL\" savename = date_stamp & "_" & "Delivery_Schedule" & ".xml" Set current = Range("F" & 2)

'******************************************************************************************** 'DEFAULT DESKTOP SAVE LOCATIONS Dim user_path As String user_path = CreateObject("WScript.Shell").specialfolders("Desktop") & "\Tariff Automation\" reference_path = user_path & "Reference Files\" save_path = user_path '********************************************************************************************

'******************************************************************************************** 'TO CHANGE THE DIRECTORY FOR SAVING XMLS AND REFERENCE FOLDER 'save_path = "INSERT COPIED PATH HERE" & "\" 'reference_path = "INSERT COPIED REFERENCE PATH HERE" & "\" '********************************************************************************************

i = 2 j = 2

'Delivery schedule xml file creation Set NewBook = Workbooks.Add With NewBook .Title = "xml 1" .SaveAs FileName:=save_path & savename, FileFormat:=xlXMLSpreadsheet End With 'Activate delivery schedule xml file and format to text (@) Workbooks(savename).Activate ActiveWorkbook.ActiveSheet.Cells.NumberFormat = "@" ActiveSheet.Name = "Data" ActiveWorkbook.Worksheets.Add ActiveSheet.Name = "Info" ActiveWorkbook.ActiveSheet.Cells.NumberFormat = "@" ActiveWorkbook.Worksheets.Add ActiveSheet.Name = "Mapping" ActiveWorkbook.ActiveSheet.Cells.NumberFormat = "@" Worksheets("Data").Activate

'Reactivate master file Workbooks("LTL Requests Log.xlsm").Activate

'Copy and paste the static information for delivery schedule xml Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("A2:N2").Copy Workbooks(savename).Worksheets("Data").Range("A1") Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("A7:B11").Copy Workbooks(savename).Worksheets("Info").Range("A1") Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("A14:C31").Copy Workbooks(savename).Worksheets("Mapping").Range("A1")

'Start copying in relevant data While current.Value <> ""

'Column A Workbooks(savename).Worksheets("Data").Range("A" & i).Value = "H" Workbooks(savename).Worksheets("Data").Range("A" & i + 1).Value = "D" 'Columns E, F, & J Workbooks(savename).Worksheets("Data").Range("E" & i).Value = current.Value Workbooks(savename).Worksheets("Data").Range("F" & i).Value = current.Value Workbooks(savename).Worksheets("Data").Range("J" & i).Value = current.Value Workbooks(savename).Worksheets("Data").Range("J" & i + 1).Value = current.Value 'Columns C & I Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Value = "=CONCATENATE(""LTL"",B" & j & ")" Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Copy Workbooks(savename).Worksheets("Data").Range("C" & i).PasteSpecial xlPasteValues Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Copy Workbooks(savename).Worksheets("Data").Range("I" & i).PasteSpecial xlPasteValues Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Copy Workbooks(savename).Worksheets("Data").Range("I" & i + 1).PasteSpecial xlPasteValues Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Value = "" 'Column G If current.Offset(0, 2).Value = "NONE" Then Workbooks(savename).Worksheets("Data").Range("G" & i).Value = "" Else Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Value = "=CONCATENATE(""LTL-"",H" & j & ",""DAY"")" Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Copy Workbooks(savename).Worksheets("Data").Range("G" & i).PasteSpecial xlPasteValues Workbooks("LTL Requests Log.xlsm").Worksheets("09.28 REQ").Range("Y" & j).Value = "" End If 'Columns K, M, & L current.Offset(0, -3).Copy Workbooks(savename).Worksheets("Data").Range("K" & i).PasteSpecial xlPasteValues current.Offset(0, -3).Copy Workbooks(savename).Worksheets("Data").Range("M" & i).PasteSpecial xlPasteValues current.Offset(0, -2).Copy Workbooks(savename).Worksheets("Data").Range("K" & i + 1).PasteSpecial xlPasteValues current.Offset(0, -2).Copy Workbooks(savename).Worksheets("Data").Range("M" & i + 1).PasteSpecial xlPasteValues Workbooks(savename).Worksheets("Data").Range("L" & i).Value = "1" Workbooks(savename).Worksheets("Data").Range("L" & i + 1).Value = "2" 'Columns D, H, & N Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("D4").Copy Workbooks(savename).Worksheets("Data").Range("D" & i) Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("H4").Copy Workbooks(savename).Worksheets("Data").Range("H" & i) Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("N4").Copy Workbooks(savename).Worksheets("Data").Range("N" & i) Workbooks("LTL Requests Log.xlsm").Worksheets("Static Info DelvSched").Range("N4").Copy Workbooks(savename).Worksheets("Data").Range("N" & i + 1) i = i + 2 j = j + 1 Set current = current.Offset(1, 0) Wend

'Activate xml file and format to text (@) Workbooks(savename).Activate ActiveWorkbook.ActiveSheet.Cells.NumberFormat = "@"

'Error handling for screen updating Application.ScreenUpdating = True errHandler: Application.ScreenUpdating = True

End Sub

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions