Still on this bit of code, time to take a break.
In the vba code section of Sheet1
partial code,
Dim ws As Worksheet:
Set ws = Sheets("EPB")
Dim LastRow As Long
Dim iFind As Range
Dim m1, m2, m3, m4, m5, m, m7, m8, m9, m10, m11, m12, m14, m15, m16, m17, m18, m19, m20, m21, m22, mOtr As Long
LastRow = ws.Range("H" & Rows.Count).End(xlUp).Row
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 01", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m1 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 2
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 02", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m2 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 03", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m3 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 04", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m4 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 05", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m5 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 06", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m6 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 07", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m7 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 08", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m8 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
iFind.FormatConditions.Delete
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 09", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m9 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 10", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m10 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 11", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m11 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 12", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m12 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 14", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m14 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 15", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m15 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 16", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m16 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 17", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m17 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 18", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m18 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 19", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m19 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 20", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m20 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 21", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m21 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:="M 22", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
m22 = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
Set iFind = ws.Range("H1:C" & LastRow).Find(What:=" ", LookIn:=xlValues, LookAt:=xlWhole)
If Not iFind Is Nothing Then
iFind.Activate
mOtr = ActiveCell.Row - 1
iFind.EntireRow.Insert Shift:=xlDown
LastRow = LastRow + 1
End If
I need to pass the variables;
Dim m1, m2, m3, m4, m5, m, m7, m8, m9, m10, m11, m12, m14, m15, m16, m17, m18, m19, m20, m21, m22, mOtr As Long
Over to the "EPB_Template" Sheet to handle the variables there;
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
With Target
If Not Application.Intersect(Target, Range("I9:I" & m1, "I" & m1+1 & ":I" & m2, "I" & m2+1 & ":I" & m3, etc , etc to , "I" & m22+1 & ":I" & mOtr, )) Is Nothing Then
Cancel = True
.Value = IIf(.Text = "IN", "OUT", "IN")
If .Value = "IN" Then
' do something
With .Interior
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Else
' do something else
With .Interior
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End With
End Sub
With the sheer amount of repetition, I still cannot find a workable loop to cut this down.
Any suggestions?
Bookmarks