Called Macro Isn't Running.

AllDay

New Member
Joined
Jul 28, 2016
Messages
12
I have the following code and want to make it run whenever any of the ranges change (specifically T5, T9, T13). I've tried multiple ways but none seem to work. The code works fine when I step through it but when I call it, it doesn't run (Refer to Below).


Code:
Sub BoldPartText1()Dim Part1Len, Part2Len, DividerLen As Integer
Dim Divider As String
Part1Len = Len(Range("T1"))
Part2Len = Len(Range("T3"))
Part3Len = Len(Range("T5"))
Part4Len = Len(Range("T7"))
Part5Len = Len(Range("T9"))
Part6Len = Len(Range("T11"))
Part7Len = Len(Range("T13"))
Part8Len = Len(Range("T15"))
Part9Len = Len(Range("T17"))


Divider = " "
DividerLen = Len(Divider)
Range("D25:N26").UnMerge
Range("D25").Clear


Range("D25") = Range("T1") & Divider & Range("T3") & Divider & Range("T5") & Divider & Range("T7") & Divider & Range("T9") & Divider & Divider & Range("T11") & Divider & Range("T13") & Divider & Range("T15") & Divider & Range("T17")


With Range("D25").Characters(Start:=1, Length:=Part1Len).Font
        .FontStyle = "Bold"
End With
With Range("D25").Characters(Start:=Part1Len + 2 + Part2Len + 1, Length:=Part3Len).Font
        .FontStyle = "Bold"
End With
With Range("D25").Characters(Start:=Part1Len + 2 + Part2Len + 1 + Part3Len + 1 + Part4Len + 1, Length:=Part5Len).Font
        .FontStyle = "Bold"
End With
With Range("D25").Characters(Start:=Part1Len + 2 + Part2Len + 1 + Part3Len + 1 + Part4Len + 1 + Part5Len + 2 + Part6Len + 1, Length:=Part7Len).Font
        .FontStyle = "Bold"
End With
With Range("D25").Characters(Start:=Part1Len + 2 + Part2Len + 1 + Part3Len + 1 + Part4Len + 1 + Part5Len + 2 + Part6Len + 1 + Part7Len + 1, Length:=Part8Len).Font
        .FontStyle = "Bold"
End With


Range("D25:N26").Merge
Range("D25").WrapText = True


End Sub



In addition to the above I have the following:

Code:
Sub Print_Hidden()   ActiveWorkbook.Unprotect "1"
   Call BoldPartText1
   MsgBox "Complete"
   Application.ScreenUpdating = False
   With Sheets("Print")
      .Visible = True
      .PrintOut Copies:=1, Collate:=True
      .Visible = False
   End With
   Application.ScreenUpdating = True
   ActiveWorkbook.Protect "1"
End Sub


This should call the above Macro to run, tell me it's completed, then print. It's just giving me the message box I click ok and it prints but none of the ranges are updated like when I step through it manually.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Are the ranges you want updated on the same sheet the code Print_Hidden is executed from? Are both routines in standard modules?
 
Upvote 0
If you want the code to run automatically when the ranges change then you need a worksheet change event.
 
Upvote 0
Are the ranges you want updated on the same sheet the code Print_Hidden is executed from? Are both routines in standard modules?


No, I have 2 Sheets in the workbook. One titled "Input" other titled "Print". Only the Input sheet is visible. It has a button that you click to Print the hidden Print Page.

Both are in Modules neither is attached to a sheet. Is that my problem?
 
Upvote 0
If you want the code to run automatically when the ranges change then you need a worksheet change event.


I tried a worksheet change, thought it could be incorrect the way I wrote it and it still wouldn't update.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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
Back
Top