M
MrRJ
Hello,
Can someone please help me interpret this code for me. What does each
section do and what is the function? The person who created this is no
longer here and I would like to understand how it works and possible make
adjustments if needed.
Thank you.
Sub CreateCSVFile()
Dim objWBPrice As Workbook
Dim objWBExport As Workbook
Dim objWSPrice As Worksheet
Dim objWSExport As Worksheet
Set objWBPrice = ActiveWorkbook
Set objWSPrice = objWBPrice.Worksheets("Price")
Set objWSExport = objWBPrice.Worksheets("CSV Export")
With objWSExport.Cells
.Clear
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 11
.ColorIndex = xlAutomatic
End With
End With
Application.ScreenUpdating = False
j = 1
For i = 2 To objWSPrice.UsedRange.Rows.Count
If objWSPrice.Cells(i, 1).Value = "Y" Then
With objWSExport
.Cells(j, 1) = objWSPrice.Cells(i, 2).Value
.Cells(j, 2) = objWSPrice.Cells(i, 3).Value
.Cells(j, 3) = objWSPrice.Cells(i, 4).Value
.Cells(j, 4) = objWSPrice.Cells(i, 5).Value
.Cells(j, 5) = objWSPrice.Cells(i, 6).Value
.Cells(j, 6) = objWSPrice.Cells(i, 7).Value
.Cells(j, 7) = objWSPrice.Cells(i, 8).Value
.Cells(j, 8) = objWSPrice.Cells(i, 9).Value
.Cells(j, 9) = objWSPrice.Cells(i, 12).Value
.Cells(j, 10) = objWSPrice.Cells(i, 15).Value
.Cells(j, 11) = objWSPrice.Cells(i, 16).Value
.Cells(j, 12) = objWSPrice.Cells(i, 17).Value
.Cells(j, 13) = objWSPrice.Cells(i, 18).Value
.Cells(j, 14) = objWSPrice.Cells(i, 19).Value
.Cells(j, 15) = objWSPrice.Cells(i, 20).Value
.Cells(j, 16) = objWSPrice.Cells(i, 21).Value
.Cells(j, 17) = objWSPrice.Cells(i, 22).Value
.Cells(j, 18) = objWSPrice.Cells(i, 23).Value
.Cells(j, 19) = objWSPrice.Cells(i, 24).Value
.Cells(j, 20) = objWSPrice.Cells(i, 25).Value
.Cells(j, 21) = objWSPrice.Cells(i, 26).Value
.Cells(j, 22) = objWSPrice.Cells(i, 27).Value
.Cells(j, 23) = objWSPrice.Cells(i, 28).Value
.Cells(j, 24) = objWSPrice.Cells(i, 29).Value
.Cells(j, 25) = objWSPrice.Cells(i, 30).Value
.Cells(j, 26) = objWSPrice.Cells(i, 31).Value
.Cells(j, 27) = objWSPrice.Cells(i, 32).Value
.Cells(j, 28) = objWSPrice.Cells(i, 33).Value
.Cells(j, 29) = objWSPrice.Cells(i, 34).Value
.Cells(j, 30) = objWSPrice.Cells(i, 35).Value
.Cells(j, 31) = objWSPrice.Cells(i, 36).Value
.Cells(j, 32) = objWSPrice.Cells(i, 37).Value
.Cells(j, 33) = objWSPrice.Cells(i, 38).Value
.Cells(j, 34) = objWSPrice.Cells(i, 39).Value
.Cells(j, 35) = objWSPrice.Cells(i, 41).Value
.Cells(j, 36) = objWSPrice.Cells(i, 48).Value
.Cells(j, 37) = objWSPrice.Cells(i, 49).Value
.Cells(j, 38) = objWSPrice.Cells(i, 50).Value
.Cells(j, 39) = objWSPrice.Cells(i, 51).Value
.Cells(j, 40) = objWSPrice.Cells(i, 52).Value
.Cells(j, 41) = objWSPrice.Cells(i, 53).Value
.Cells(j, 42) = objWSPrice.Cells(i, 54).Value
.Cells(j, 43) = objWSPrice.Cells(i, 55).Value
.Cells(j, 44) = objWSPrice.Cells(i, 56).Value
.Cells(j, 45) = objWSPrice.Cells(i, 57).Value
.Cells(j, 46) = objWSPrice.Cells(i, 58).Value
.Cells(j, 47) = objWSPrice.Cells(i, 59).Value
.Cells(j, 48) = objWSPrice.Cells(i, 60).Value
.Cells(j, 49) = objWSPrice.Cells(i, 61).Value
.Cells(j, 50) = objWSPrice.Cells(i, 62).Value
.Cells(j, 51) = objWSPrice.Cells(i, 63).Value
.Cells(j, 52) = objWSPrice.Cells(i, 64).Value
.Cells(j, 53) = objWSPrice.Cells(i, 65).Value
.Cells(j, 54) = objWSPrice.Cells(i, 66).Value
.Cells(j, 55) = objWSPrice.Cells(i, 67).Value
.Cells(j, 56) = objWSPrice.Cells(i, 68).Value
.Cells(j, 57) = objWSPrice.Cells(i, 69).Value
.Cells(j, 58) = objWSPrice.Cells(i, 70).Value
.Cells(j, 59) = objWSPrice.Cells(i, 71).Value
.Cells(j, 60) = objWSPrice.Cells(i, 72).Value
.Cells(j, 61) = objWSPrice.Cells(i, 73).Value
.Cells(j, 62) = objWSPrice.Cells(i, 74).Value
.Cells(j, 63) = objWSPrice.Cells(i, 75).Value
.Cells(j, 64) = objWSPrice.Cells(i, 76).Value
.Cells(j, 65) = objWSPrice.Cells(i, 77).Value
.Cells(j, 66) = objWSPrice.Cells(i, 78).Value
.Cells(j, 67) = objWSPrice.Cells(i, 79).Value
.Cells(j, 68) = objWSPrice.Cells(i, 80).Value
.Cells(j, 69) = objWSPrice.Cells(i, 81).Value
.Cells(j, 70) = objWSPrice.Cells(i, 82).Value
.Cells(j, 71) = objWSPrice.Cells(i, 83).Value
.Cells(j, 72) = objWSPrice.Cells(i, 84).Value
.Cells(j, 73) = objWSPrice.Cells(i, 85).Value
.Cells(j, 74) = objWSPrice.Cells(i, 86).Value
.Cells(j, 75) = objWSPrice.Cells(i, 87).Value
.Cells(j, 76) = objWSPrice.Cells(i, 88).Value
.Cells(j, 77) = objWSPrice.Cells(i, 89).Value
j = j + 1
End With
End If
Next i
With objWSExport
.Visible = True
.Activate
.Copy
End With
Set objWBExport = ActiveWorkbook
strPath = objWBPrice.Path & Chr(92)
strFilename = strPath & Left(objWBPrice.Name, Len(objWBPrice.Name) - 4)
objWBExport.SaveAs Filename:=strFilename, FileFormat:=xlCSV
MsgBox "File Creation Complete", vbOKOnly, "CSV File"
objWSExport.Visible = False
End Sub
Can someone please help me interpret this code for me. What does each
section do and what is the function? The person who created this is no
longer here and I would like to understand how it works and possible make
adjustments if needed.
Thank you.
Sub CreateCSVFile()
Dim objWBPrice As Workbook
Dim objWBExport As Workbook
Dim objWSPrice As Worksheet
Dim objWSExport As Worksheet
Set objWBPrice = ActiveWorkbook
Set objWSPrice = objWBPrice.Worksheets("Price")
Set objWSExport = objWBPrice.Worksheets("CSV Export")
With objWSExport.Cells
.Clear
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 11
.ColorIndex = xlAutomatic
End With
End With
Application.ScreenUpdating = False
j = 1
For i = 2 To objWSPrice.UsedRange.Rows.Count
If objWSPrice.Cells(i, 1).Value = "Y" Then
With objWSExport
.Cells(j, 1) = objWSPrice.Cells(i, 2).Value
.Cells(j, 2) = objWSPrice.Cells(i, 3).Value
.Cells(j, 3) = objWSPrice.Cells(i, 4).Value
.Cells(j, 4) = objWSPrice.Cells(i, 5).Value
.Cells(j, 5) = objWSPrice.Cells(i, 6).Value
.Cells(j, 6) = objWSPrice.Cells(i, 7).Value
.Cells(j, 7) = objWSPrice.Cells(i, 8).Value
.Cells(j, 8) = objWSPrice.Cells(i, 9).Value
.Cells(j, 9) = objWSPrice.Cells(i, 12).Value
.Cells(j, 10) = objWSPrice.Cells(i, 15).Value
.Cells(j, 11) = objWSPrice.Cells(i, 16).Value
.Cells(j, 12) = objWSPrice.Cells(i, 17).Value
.Cells(j, 13) = objWSPrice.Cells(i, 18).Value
.Cells(j, 14) = objWSPrice.Cells(i, 19).Value
.Cells(j, 15) = objWSPrice.Cells(i, 20).Value
.Cells(j, 16) = objWSPrice.Cells(i, 21).Value
.Cells(j, 17) = objWSPrice.Cells(i, 22).Value
.Cells(j, 18) = objWSPrice.Cells(i, 23).Value
.Cells(j, 19) = objWSPrice.Cells(i, 24).Value
.Cells(j, 20) = objWSPrice.Cells(i, 25).Value
.Cells(j, 21) = objWSPrice.Cells(i, 26).Value
.Cells(j, 22) = objWSPrice.Cells(i, 27).Value
.Cells(j, 23) = objWSPrice.Cells(i, 28).Value
.Cells(j, 24) = objWSPrice.Cells(i, 29).Value
.Cells(j, 25) = objWSPrice.Cells(i, 30).Value
.Cells(j, 26) = objWSPrice.Cells(i, 31).Value
.Cells(j, 27) = objWSPrice.Cells(i, 32).Value
.Cells(j, 28) = objWSPrice.Cells(i, 33).Value
.Cells(j, 29) = objWSPrice.Cells(i, 34).Value
.Cells(j, 30) = objWSPrice.Cells(i, 35).Value
.Cells(j, 31) = objWSPrice.Cells(i, 36).Value
.Cells(j, 32) = objWSPrice.Cells(i, 37).Value
.Cells(j, 33) = objWSPrice.Cells(i, 38).Value
.Cells(j, 34) = objWSPrice.Cells(i, 39).Value
.Cells(j, 35) = objWSPrice.Cells(i, 41).Value
.Cells(j, 36) = objWSPrice.Cells(i, 48).Value
.Cells(j, 37) = objWSPrice.Cells(i, 49).Value
.Cells(j, 38) = objWSPrice.Cells(i, 50).Value
.Cells(j, 39) = objWSPrice.Cells(i, 51).Value
.Cells(j, 40) = objWSPrice.Cells(i, 52).Value
.Cells(j, 41) = objWSPrice.Cells(i, 53).Value
.Cells(j, 42) = objWSPrice.Cells(i, 54).Value
.Cells(j, 43) = objWSPrice.Cells(i, 55).Value
.Cells(j, 44) = objWSPrice.Cells(i, 56).Value
.Cells(j, 45) = objWSPrice.Cells(i, 57).Value
.Cells(j, 46) = objWSPrice.Cells(i, 58).Value
.Cells(j, 47) = objWSPrice.Cells(i, 59).Value
.Cells(j, 48) = objWSPrice.Cells(i, 60).Value
.Cells(j, 49) = objWSPrice.Cells(i, 61).Value
.Cells(j, 50) = objWSPrice.Cells(i, 62).Value
.Cells(j, 51) = objWSPrice.Cells(i, 63).Value
.Cells(j, 52) = objWSPrice.Cells(i, 64).Value
.Cells(j, 53) = objWSPrice.Cells(i, 65).Value
.Cells(j, 54) = objWSPrice.Cells(i, 66).Value
.Cells(j, 55) = objWSPrice.Cells(i, 67).Value
.Cells(j, 56) = objWSPrice.Cells(i, 68).Value
.Cells(j, 57) = objWSPrice.Cells(i, 69).Value
.Cells(j, 58) = objWSPrice.Cells(i, 70).Value
.Cells(j, 59) = objWSPrice.Cells(i, 71).Value
.Cells(j, 60) = objWSPrice.Cells(i, 72).Value
.Cells(j, 61) = objWSPrice.Cells(i, 73).Value
.Cells(j, 62) = objWSPrice.Cells(i, 74).Value
.Cells(j, 63) = objWSPrice.Cells(i, 75).Value
.Cells(j, 64) = objWSPrice.Cells(i, 76).Value
.Cells(j, 65) = objWSPrice.Cells(i, 77).Value
.Cells(j, 66) = objWSPrice.Cells(i, 78).Value
.Cells(j, 67) = objWSPrice.Cells(i, 79).Value
.Cells(j, 68) = objWSPrice.Cells(i, 80).Value
.Cells(j, 69) = objWSPrice.Cells(i, 81).Value
.Cells(j, 70) = objWSPrice.Cells(i, 82).Value
.Cells(j, 71) = objWSPrice.Cells(i, 83).Value
.Cells(j, 72) = objWSPrice.Cells(i, 84).Value
.Cells(j, 73) = objWSPrice.Cells(i, 85).Value
.Cells(j, 74) = objWSPrice.Cells(i, 86).Value
.Cells(j, 75) = objWSPrice.Cells(i, 87).Value
.Cells(j, 76) = objWSPrice.Cells(i, 88).Value
.Cells(j, 77) = objWSPrice.Cells(i, 89).Value
j = j + 1
End With
End If
Next i
With objWSExport
.Visible = True
.Activate
.Copy
End With
Set objWBExport = ActiveWorkbook
strPath = objWBPrice.Path & Chr(92)
strFilename = strPath & Left(objWBPrice.Name, Len(objWBPrice.Name) - 4)
objWBExport.SaveAs Filename:=strFilename, FileFormat:=xlCSV
MsgBox "File Creation Complete", vbOKOnly, "CSV File"
objWSExport.Visible = False
End Sub