Skip to content

Commit eaebbb9

Browse files
authored
Update personal_macro_workbook.vb
1 parent 49c879f commit eaebbb9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

personal_macro_workbook.vb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Option Explicit
2020
Dim a0 As Single, a1 As Single, a2 As Single, fitLimit As Single, mfp As Single, peX As Single
2121

2222
Sub CLAM2()
23-
ver = "8.42p" ' Version of this code.
23+
ver = "8.43p" ' Version of this code.
2424
If Application.OperatingSystem Like "*Mac*" Then
2525
backSlash = "/"
2626
Else
@@ -302,6 +302,7 @@ DeadInTheWater3:
302302
strSheetAnaName = "Exp_" + strSheetDataName
303303
strSheetGraphName = "Graph_" + strSheetDataName
304304
Call ExportCmp("")
305+
ActiveWorkbook.Save
305306
If Len(strErr) > 0 Then Exit Sub
306307
ElseIf StrComp(LCase(Cells(1, 1).Value), "norm", 1) = 0 Or StrComp(LCase(Cells(1, 1).Value), "edge", 1) = 0 Or StrComp(LCase(Cells(1, 1).Value), "diff", 1) = 0 Then
307308
Call GetNormalize
@@ -310,11 +311,13 @@ DeadInTheWater3:
310311
strSheetGraphName = "Graph_" + strSheetDataName
311312
Call GetAutoScale
312313
If StrComp(mid$(strErr, 1, 3), "err", 1) = 0 Then MsgBox ("Error in range: " & mid$(strErr, 4, Len(strErr) - 3))
314+
ActiveWorkbook.Save
313315
If Len(strErr) > 0 Then Exit Sub
314316
ElseIf StrComp(LCase(mid$(Cells(1, 1).Value, 1, 3)), "leg", 1) = 0 Then
315317
strSheetGraphName = "Graph_" + strSheetDataName
316318
Results = vbNullString
317319
Call CombineLegend
320+
ActiveWorkbook.Save
318321
End
319322
ElseIf StrComp(LCase(Cells(1, 1).Value), "debug", 1) = 0 Then
320323
Cells(1, 1).Value = "Grating"
@@ -370,6 +373,7 @@ DeadInTheWater3:
370373
strSheetGraphName = "Cmp_" + strSheetDataName
371374
Results = vbNullString
372375
Call CombineLegend
376+
ActiveWorkbook.Save
373377
End
374378
ElseIf StrComp(LCase(mid$(Cells(1, 1).Value, 1, 4)), "auto", 1) = 0 Then
375379
strSheetGraphName = "Cmp_" + strSheetDataName
@@ -381,6 +385,7 @@ DeadInTheWater3:
381385
strSheetGraphName = "Cmp_" + strSheetDataName
382386
ncomp = Range(Cells(10, 1), Cells(10, 1).End(xlToRight)).Columns.Count / 3
383387
Call ExportCmp("")
388+
ActiveWorkbook.Save
384389
If Len(strErr) > 0 Then Exit Sub
385390
End If
386391

@@ -450,7 +455,8 @@ DeadInTheWater3:
450455
Cells(1, 4).Value = "Name"
451456
Call ExportLmfit
452457
Application.CutCopyMode = False
453-
End
458+
strErr = "exported"
459+
If Len(strErr) > 0 Then Exit Sub
454460
Else
455461
If InStr(1, sh, "Fit_BE") > 0 Then
456462
strMode = "Do fit range"
@@ -5091,6 +5097,8 @@ Resolve:
50915097
Cells(15 + sftfit2, n - iCol + 110).Value = ratio(iRow - iCol) / ratio(k)
50925098
Else
50935099
If Cells(6, n - iCol).Font.Bold = False Then
5100+
If Cells(6, n - iRow + k).Value <= 0.00001 Then Cells(6, n - iRow + k).Value = (Cells(3, 101).Value - Cells(2, 101).Value) / 100
5101+
' above avoids reference amplitude to be minimum at 1e-6, then make certain value if less than 1e-5.
50945102
SolverAdd CellRef:=Cells(6, n - iCol), Relation:=2, FormulaText:=Cells(6, n - iRow + k) * ratio(iRow - iCol) / ratio(k)
50955103
End If
50965104
Cells(15 + sftfit2, n - iCol + 110).Value = ratio(iRow - iCol) / ratio(k)
@@ -8433,7 +8441,7 @@ End Sub
84338441

84348442
Sub SolverSetup() ' simple results with quick time
84358443
SolverReset ' Error due to the Solver installation! Check the Solver function correctly installed.
8436-
SolverOptions MaxTime:=10, Iterations:=100, Precision:=0.01, AssumeLinear _
8444+
SolverOptions MaxTime:=10, Iterations:=100, Precision:=0.001, AssumeLinear _
84378445
:=False, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _
84388446
IntTolerance:=5, Scaling:=True, Convergence:=0.01, AssumeNonNeg:=False, Multistart:=False
84398447
End Sub
@@ -10107,7 +10115,7 @@ Sub CombineLegend() ' no k is used because from GetCompare Sub
1010710115
Set sheetTarget = Worksheets(strSheetTargetName)
1010810116
ncomp = sheetTarget.Cells(45, para + 10).Value
1010910117

10110-
If ncomp > 0 Then
10118+
If ncomp >= 0 Then
1011110119
If ExistSheet(strSheetSampleName) = False Then
1011210120
Worksheets.Add().Name = strSheetSampleName
1011310121
Set sheetSample = Worksheets(strSheetSampleName)
@@ -10167,9 +10175,11 @@ Sub CombineLegend() ' no k is used because from GetCompare Sub
1016710175
Set sheetSample = Worksheets(strSheetSampleName)
1016810176
sheetTarget.Activate
1016910177

10170-
For n = 0 To ncomp - 1
10171-
sheetTarget.Cells(1, 5 + n * 3) = sheetSample.Cells(n + 3, 2).Value & spr & sheetSample.Cells(n + 3, 4).Value
10172-
Next
10178+
If ncomp > 0 Then
10179+
For n = 0 To ncomp - 1
10180+
sheetTarget.Cells(1, 5 + n * 3) = sheetSample.Cells(n + 3, 2).Value & spr & sheetSample.Cells(n + 3, 4).Value
10181+
Next
10182+
End If
1017310183

1017410184
If ActiveSheet.ChartObjects.Count > 0 Then
1017510185
For n = 0 To ActiveSheet.ChartObjects.Count - 1

0 commit comments

Comments
 (0)