New to VBA and not sure what the code I have is doing
I have gotten a project at work and I need to change this code up a little bit but I'm not sure exactly how it is working. It is somehow taking data from another excel and importing it in another excel file. If somebody could give me some info on hos this is working that would be greatly appreciated. The codes looks like this
'Sub ReadAirfoilReport()
'Private Sub CommandButton4_Click()
Dim Chrt As Chart
'Dim Dict As Object
Set Dict = CreateObject("Scripting.Dictionary")
'Number = "CBDUCU3179"
'mainpage = Workbooks("Auto-Find Dovetail Deviations").Name
'mainsheet = Workbooks("Auto-Find Dovetail Deviations").Worksheets("Data").Name
Workbooks(mainpage).Worksheets("Sheet3").Range("A1:E200").ClearContents
'With Application.FileSearch
'Search for a files that contains this number
Application.FileSearch.Filename = "*" & Number & ".xls" & "*"
'Inside this folder
'.LookIn = "S:\eng\MFG\GP7000\test\"
Application.FileSearch.LookIn = "S:\qual\26_Customer Quality Submittals\GP7000\EQN Final Folder\New Test\" & Number & "\"
'And all sub folders
'\\pwr-eng01-tvl\eng\MFG\GP7000\EQN Final Folder
Application.FileSearch.SearchSubFolders = True
'Execute the search, sort the result newest files first
FoundFiles = Application.FileSearch.Execute(msoSortByLastModified, msoSortOrderDescending)
If FoundFiles = 0 Then
' MsgBox "No Airfoil files found"
ElseIf FoundFiles <> 0 Then
AirfoilXLS = Application.FileSearch.FoundFiles(1)
' End With
'AirfoilXLS = Application.GetOpenFilename(Title:="Select Airfoil Report")
check1 = False
'If AirfoilXLS = False Then
'Exit Sub
'End If
Workbooks.Open (AirfoilXLS)
book_name = ActiveWorkbook.Name
sheet_name = ActiveSheet.Name
Count = 10
For Each Chrt In Charts
Dict.RemoveAll
Workbooks(mainpage).Worksheets("Sheet3").Range("a1:d50").ClearContents
' Selection.ClearContents
'
' series Macro
' Macro recorded 10/26/2012 by dmoell
'
'Dim Chrt As Chart
'Dim seriescoll As Variant
'For Each Chrt In Charts
' seriescoll = Chrt.SeriesCollection(1).XValues
' MsgBox (seriescoll.XValues)
' For Each c In seriescoll
'Next
'
Dim NumberOfRows As Integer
Dim X As Object
Counter = 2
' Calculate the number of rows of data.
NumberOfRows = UBound(Chrt.SeriesCollection(1).Values)
chart_name = Chrt.Name
run_check = True
If chart_name Like "FULL_DEV*" Or chart_name Like "LE_RADIUS_PLOT*" Or chart_name Like "TANGENT_ANGLE_PLOT*" Or chart_name Like "CHORD_ANGLE_PLOT*" Or chart_name Like "W_DIMENSION_PLOT*" Or chart_name Like "MAX_THICKNESS_PLOT*" Or chart_name Like "LE_LFA_PLOT*" Or chart_name Like "TE_LFA_PLOT*" Or chart_name Like "TE_RADIUS_PLOT*" Or chart_name Like "ADJUSTED_X_PLOT*" Or chart_name Like "ADJUSTED_Y_PLOT*" Then
run_check = False
End If
If run_check = True Then
Workbooks(mainpage).Worksheets("Sheet3").Cells(1, 1) = chart_name
' Write x-axis values to worksheet.
With Workbooks(mainpage).Worksheets("Sheet3")
.Range(.Cells(2, 1), _
.Cells(NumberOfRows + 1, 1)) = _
Application.Transpose(Chrt.SeriesCollection(1).XValues)
End With
' Loop through all series in the chart and write their values to
' the worksheet.
For Each X In Chrt.SeriesCollection
Workbooks(mainpage).Worksheets("Sheet3").Cells(1, Counter) = X.Name
With Workbooks(mainpage).Worksheets("Sheet3")
.Range(.Cells(2, Counter), _
.Cells(NumberOfRows + 1, Counter)) = _
Application.Transpose(X.Values)
End With
Counter = Counter + 1
Next
check = False
For Each c In Workbooks(mainpage).Worksheets("Sheet3").Range("B2:B41")
If c.Value <> "" And Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 1).Value < -9.9 Then
Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 1).Value = -10000
End If
If c.Value <> "" And Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 2).Value > 9.9 Then
Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 2).Value = 10000
End If
If c.Value < Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 1).Value Then
section = Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column - 1).Value
Dict.Add chart_name & " " & section, c.Value
checkall = True
check = True
check1 = True
ElseIf c.Value > Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column + 2).Value Then
section = Workbooks(mainpage).Worksheets("Sheet3").Cells(c.Row, c.Column - 1).Value
Dict.Add chart_name & " " & section, c.Value
checkall = True
check = True
check1 = True
End If
Next
If check = True Then
Workbooks(mainpage).Worksheets(mainsheet).Cells(10, Count) = Workbooks(mainpage).Worksheets("Sheet3").Cells(1, 1)
Keys = Dict.Keys
Items = Dict.Items
' For R = 0 To UBound(Keys)
' MsgBox (Keys(R))
'Next
Workbooks(mainpage).Worksheets(mainsheet).Cells(11, Count).Resize(UBound(Keys) - LBound(Keys) + 1, 1) = WorksheetFunction.Transpose(Keys)
Workbooks(mainpage).Worksheets(mainsheet).Cells(11, Count + 1).Resize(UBound(Items) - LBound(Items) + 1, 1) = WorksheetFunction.Transpose(Items)
With Workbooks(SSbook).Worksheets(SSheet)
For i = 0 To UBound(Keys)
stringtofind = Keys(i)
Set section = .Range("G:G").Find(stringtofind)
If Not section Is Nothing Then
destRow = section.Row
If Keys(i) Like "H_ANGLE_PLOT*" Or Keys(i) Like "XLET_1_0.0150_PLOT*" Or Keys(i) Like "XLET_4_0.6000*" Or Keys(i) Like "M_DIMENSION_PLOT*" Or Keys(i) Like "XLET_2_0.0450_PLOT*" Or Keys(i) Like "XLET_3_0.3000_PLOT*" Or Keys(i) Like "XTET_1_0.0300_PLOT*" Or Keys(i) Like "U_THICKNESS_0.2000_PLOT*" Or Keys(i) Like "V_THICKNESS_0.1480_PLOT*" Or Keys(i) Like "N_ANGLE_PLOT*" Or Keys(i) Like "A_ANGLE_PLOT*" Or Keys(i) Like "XLET_5_0.5000_PLOT*" Or Keys(i) Like "XLET_6_2.0000_PLOT*" Then
Items(i) = .Cells(destRow, 8) + Items(i)
End If
.Cells(destRow, destColumn).Value = Items(i)
ElseIf section Is Nothing Then
NumSection = Number & " " & Keys(i)
DictAirfoilDEV.Add NumSection, " Not Found" & " = " & Items(i)
AirfoilDEV = True
End If
Next
End With
Count = Count + 3
End If
'Workbooks(mainpage).Worksheets("Sheet2").Activate
'MsgBox ("Check")
Workbooks(mainpage).Worksheets("Sheet3").Range("a1:d50").ClearContents
End If
Next
If check1 = False Then
'MsgBox ("No Deviations Found")
End If
Workbooks(book_name).Close False
Workbooks(mainpage).Worksheets("Sheet1").Activate
End If
'If checkall = False Then
'MsgBox (Number & " has no deviations.")
'End If
End If
Next
Workbooks(SSbook).Save
Workbooks(SSbook).Close True
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago