Option Explicit
Sub Modified_aaa_v2()
'JumpTo label naming by calibration name and data entry to excel PPG file
'Add Calibration label name for Jumpto Name. Example: (CAL_1) or (QUA_1), _
etc. except do not use (QUA_1a).
Dim xlCalc As XlCalculation
Dim RwIndex As Long
Dim LRow As Long
Dim sCalName As String
Dim ShtToChange As Worksheet
Dim RwOffset As Long
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
On Error GoTo ExitPoint
Set ShtToChange = ThisWorkbook.Worksheets("Sheet1")
With ShtToChange
LRow = .Range("A1").End(xlDown).Row
'sample search string. MEAS/SPHERE,F(QUA_1),5
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
If Left(.Value2, 13) = "MEAS/SPHERE,F" Then
'find left "(" and then right ")" string example: "(CAL_1)"
sCalName = Mid(.Value2, InStr(.Value2, "("), InStr(.Value2, ")") - InStr(.Value2, "(") + 1)
End If
'Add calibration label name. example: (QUA_1)
If sCalName <> "(QUA_1)" Then
If Left(.Value2, 8) = "SNSLCT/S" Then
If .Value2 <> "SNSLCT/S(S1)" Then
.EntireRow.Insert Shift:=xlDown
RwOffset = -1
End If
With .Offset(RwOffset, 0)
If .Offset(-1, 0).Value2 <> "RECALL/D(COORD1),DISK" Then
.Value2 = sCalName
Else
Stop
End If
End With
End If
End If
End With
Next RwIndex
'Add "RECALL/D(COORD1),DISK" after new Jumpto label name
'sample search string. MEAS/SPHERE,F(QUA_1),5
LRow = .Range("A1").End(xlDown).Row
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
Select Case True
Case Left(.Value2, 13) = "MEAS/SPHERE,F"
If .Offset(-1, 0).Value2 <> "RECALL/D(COORD1),DISK" Then
'find left "(" and then right ")" string example: "(CAL_1)"
sCalName = Mid(.Value2, InStr(.Value2, "("), InStr(.Value2, ")") - InStr(.Value2, "(") + 1)
End If
Case Left(.Value2, 8) = "SNSLCT/S"
With .Offset(-1, 0)
If .Value2 = sCalName Then
If .Value2 <> "(QUA_1)" Then
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
' RwOffset = -1
.Offset(1, 0).Value2 = "RECALL/D(COORD1),DISK"
Else
Stop
End If
End If
End With
Case Else
'do nothing
End Select
End With
Next RwIndex
'Re-run loop for (QUA_1) label
LRow = .Range("A1").End(xlDown).Row
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
If .Value2 = "MEAS/SPHERE,F(QUA_1),5" Then
With .Offset(-2, 0)
If Right(.Offset(-1, 0).Value2, 7) <> "-0.4999" Then
.EntireRow.Insert Shift:=xlDown
RwOffset = -1
.Offset(RwOffset, 0).Value2 = "(QUA_1)"
End If
End With
End If
End With
Next RwIndex
.Range("A1").Activate
End With
ExitPoint:
With Application
.Calculation = xlCalc
.ScreenUpdating = True
.EnableEvents = True
End With
Set ShtToChange = Nothing
Application.ScreenUpdating = True
MsgBox "done"
End Sub
Sub Modified_aaa_v1()
'JumpTo label naming by calibration name and data entry to excel PPG file
'Add Calibration label name for Jumpto Name. Example: (CAL_1) or (QUA_1), _
etc. except do not use (QUA_1a).
Dim xlCalc As XlCalculation
Dim RwIndex As Long
Dim LRow As Long
Dim sCalName As String
Dim ShtToChange As Worksheet
Dim RwOffset As Long
With Application
xlCalc = .Calculation
' .Calculation = xlCalculationManual
' .ScreenUpdating = False
.EnableEvents = False
End With
On Error GoTo ExitPoint
Set ShtToChange = ThisWorkbook.Worksheets("Sheet1")
With ShtToChange
LRow = .Range("A1").End(xlDown).Row
'sample search string. MEAS/SPHERE,F(QUA_1),5
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
If Left(.Value2, 13) = "MEAS/SPHERE,F" Then
'find left "(" and then right ")" string example: "(CAL_1)"
sCalName = Mid(.Value2, InStr(.Value2, "("), InStr(.Value2, ")") - InStr(.Value2, "(") + 1)
End If
'Add calibration label name. example: (QUA_1)
If sCalName <> "(QUA_1)" Then
If Left(.Value2, 8) = "SNSLCT/S" Then
If .Value2 <> "SNSLCT/S(S1)" Then
.EntireRow.Insert Shift:=xlDown
RwOffset = -1
End If
With .Offset(RwOffset, 0)
If .Offset(-1, 0).Value2 <> "RECALL/D(COORD1),DISK" Then
.Value2 = sCalName
Else
Stop
End If
End With
End If
End If
End With
Next RwIndex
'Add "RECALL/D(COORD1),DISK" after new Jumpto label name
'sample search string. MEAS/SPHERE,F(QUA_1),5
LRow = .Range("A1").End(xlDown).Row
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
Select Case True
Case Left(.Value2, 13) = "MEAS/SPHERE,F"
If .Offset(-1, 0).Value2 <> "RECALL/D(COORD1),DISK" Then
'find left "(" and then right ")" string example: "(CAL_1)"
sCalName = Mid(.Value2, InStr(.Value2, "("), InStr(.Value2, ")") - InStr(.Value2, "(") + 1)
End If
Case Left(.Value2, 8) = "SNSLCT/S"
With .Offset(-1, 0)
If .Value2 = sCalName Then
If .Value2 <> "(QUA_1)" Then
.Offset(1, 0).EntireRow.Insert Shift:=xlDown
' RwOffset = -1
.Offset(1, 0).Value2 = "RECALL/D(COORD1),DISK"
Else
End If
End If
End With
Case Else
'do nothing
End Select
End With
Next RwIndex
'Re-run loop for (QUA_1) label
LRow = .Range("A1").End(xlDown).Row
For RwIndex = LRow To 2 Step -1
RwOffset = 0
With .Cells(RwIndex, "A")
If .Value2 = "MEAS/SPHERE,F(QUA_1),5" Then
With .Offset(-2, 0)
If Right(.Offset(-1, 0).Value2, 7) <> "-0.4999" Then
.EntireRow.Insert Shift:=xlDown
RwOffset = -1
.Offset(RwOffset, 0).Value2 = "(QUA_1)"
End If
End With
End If
End With
Next RwIndex
.Range("A1").Activate
End With
ExitPoint:
With Application
.Calculation = xlCalc
.ScreenUpdating = True
.EnableEvents = True
End With
Set ShtToChange = Nothing
Application.ScreenUpdating = True
MsgBox "done"
End Sub
hth
Bookmarks