Compile error / prosedure too large

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows
Hi
I have a table with 7 x 5 rows, 6-10,12-16, 18-22, 24-28, 30-34, 36-40 and 42-46 (Total 35 rows)
For each row this procedure is made (example below is to row 46):
The procedure works fine on 34 rows (random pick), but not when I hardcode the 35th...
I am searching this forum for some guiding out of this problem - can anybody help me?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 2/26/2020 10:33:36 PM EST
'ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingColumns:=True, AllowFormattingRows:=True
Application.ScreenUpdating = False

If Not Intersect(Target, Range("B46")) Is Nothing Then
Cancel = True
Range("B46").Value = Range("B4").Value + 1
Range("C46").Select
End If

If Not Intersect(Target, Range("C46")) Is Nothing Then
Cancel = True
Range("B46:B46").ClearContents
Range("B46").Value = Range("B4").Value + 1
Range("C46").Copy
Sheets("Fordeling").Range("FordelingKodeSubArea") = Sheets("Reg").Range("C46") 'value'PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ArbeidsArtListe
Range("E46").Value = Sheets("Fordeling").Range("FordelingKopiStart").Value
Range("E46").Select
Range("J46").Value = "Ferdig"
Range("L46").Value = Time
End If

If Not Intersect(Target, Range("J46")) Is Nothing Then
Cancel = True
Range("J46").Value = "Ferdig"
Range("M46").Value = Time
Range("M46").Select

End If

If Not Intersect(Target, Range("K46")) Is Nothing Then
Cancel = True
KjøreListeReg
End If

If Not Intersect(Target, Range("L46")) Is Nothing Then
Cancel = True
ActiveCell.Value = Time
Range("L46").Select
End If

If Not Intersect(Target, Range("M46")) Is Nothing Then
Cancel = True
ActiveCell.Value = Time
Range("M46").Select
End If
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows
Hi
I have a table with 7 x 5 rows, 6-10,12-16, 18-22, 24-28, 30-34, 36-40 and 42-46 (Total 35 rows)
For each row this procedure is made (example below is to row 46):
The procedure works fine on 34 rows (random pick), but not when I hardcode the 35th...
I am searching this forum for some guiding out of this problem - can anybody help me?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 2/26/2020 10:33:36 PM EST
'ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingColumns:=True, AllowFormattingRows:=True
Application.ScreenUpdating = False

If Not Intersect(Target, Range("B46")) Is Nothing Then
Cancel = True
Range("B46").Value = Range("B4").Value + 1
Range("C46").Select
End If

If Not Intersect(Target, Range("C46")) Is Nothing Then
Cancel = True
Range("B46:B46").ClearContents
Range("B46").Value = Range("B4").Value + 1
Range("C46").Copy
Sheets("Fordeling").Range("FordelingKodeSubArea") = Sheets("Reg").Range("C46") 'value'PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ArbeidsArtListe
Range("E46").Value = Sheets("Fordeling").Range("FordelingKopiStart").Value
Range("E46").Select
Range("J46").Value = "Ferdig"
Range("L46").Value = Time
End If

If Not Intersect(Target, Range("J46")) Is Nothing Then
Cancel = True
Range("J46").Value = "Ferdig"
Range("M46").Value = Time
Range("M46").Select

End If

If Not Intersect(Target, Range("K46")) Is Nothing Then
Cancel = True
KjøreListeReg
End If

If Not Intersect(Target, Range("L46")) Is Nothing Then
Cancel = True
ActiveCell.Value = Time
Range("L46").Select
End If

If Not Intersect(Target, Range("M46")) Is Nothing Then
Cancel = True
ActiveCell.Value = Time
Range("M46").Select
End If
Application.ScreenUpdating = True
End Sub
Can I simplyfy the procedure by change the row indicator with a variable (=active row)?
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
See if this modified version works for you.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 12/16/2020
'ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingColumns:=True, AllowFormattingRows:=True
Application.ScreenUpdating = False
If Not Intersect(Target, Range("B46")) Is Nothing Then
    Cancel = True
    Range("B46").Value = Range("B4").Value + 1
    Range("B46:B46").ClearContents
    Range("B46").Value = Range("B4").Value + 1
    Range("C46").Copy
    Sheets("Fordeling").Range("FordelingKodeSubArea") = Sheets("Reg").Range("C46") 'value'PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    ArbeidsArtListe
    Range("E46").Value = Sheets("Fordeling").Range("FordelingKopiStart").Value
    Range("E46").Select
    Range("J46").Value = "Ferdig"
    Range("L46").Value = Time
    Range("J46").Value = "Ferdig"
    Range("M46").Value = Time
    KjøreListeReg
    ActiveCell.Value = Time
    ActiveCell.Value = Time
    Range("M46").Select
End If
Application.ScreenUpdating = True
End Sub
 

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows
Thanks for trying, but this is procedure does not do the actions correctly. Sorry
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

Thanks for trying, but this is procedure does not do the actions correctly. Sorry
Yes, I see that my failing eyesight has once again betrayed me. After closer inspection, I see that when certain condititions are true, the code could call two other procedures. Have you looked at them to determine if they might be the souce of the problem?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
Maybe something like
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingColumns:=True, AllowFormattingRows:=True
Application.ScreenUpdating = False
Dim Rw As Long
Rw = Target.Row

If Not Intersect(Target, Range("B6:B46")) Is Nothing Then
Cancel = True
Range("B" & Rw).Value = Range("B4").Value + 1
Range("C" & Rw).Select
End If
 

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Thanks again :)
I'll try this one in a couple of days
 

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows
Brilliant!! :)
This seems to make the trick
Thanks a lot
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
524
Office Version
  1. 365
Platform
  1. Windows
Rw = Target.Row

One more question: What do I do to copy a value from (Range("M" & Rw) to Range("L"& row +1)?
Expression Range("L" & Rw + 1).Value = .... does not work
 

Watch MrExcel Video

Forum statistics

Threads
1,129,502
Messages
5,636,696
Members
416,935
Latest member
Atulcp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top