Applying Worksheet Code to All Worksheets

I have some rather lengthy code I tested on a single worksheet in a workbook with 110 sheets. here is the code:
Private Sub Worksheet_Change(ByVal target As Range)
If sysgroup = False Or syscater = False Or syscake = False Then
If Intersect(target, Range("A4:B39", "H4:I25")) Is Nothing Or target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
With target
If target.Column = 5 Or target.Column = 11 Then
If target.Column = 5 Then
target.HorizontalAlignment = xlCenter
If Columns("E").ColumnWidth <> 6 Then
Columns("E").ColumnWidth = 6
End If
Else
target.HorizontalAlignment = xlCenter
If Columns("K").ColumnWidth <> 6 Then
Columns("K").ColumnWidth = 6
End If
End If
End If
If target.Column = 6 Or target.Column = 12 Then
If target.Column = 6 Then
target.HorizontalAlignment = xlCenter
Columns("F").AutoFit
If Columns("F").ColumnWidth <> 6.75 Then
Columns("F").ColumnWidth = 6.75
End If
Else
target.HorizontalAlignment = xlCenter
Columns("L").AutoFit
If Columns("L").ColumnWidth <> 6.75 Then
Columns("L").ColumnWidth = 6.75
End If
End If
target.Value = UCase(target.Value)
Else
target.Value = WorksheetFunction.Proper(target.Value)
End If
With .Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 90
.Gradient.ColorStops.Clear
End With
With .Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With .Interior.Gradient.ColorStops.Add(0.5)
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.599993896298105
End With
With .Interior.Gradient.ColorStops.Add(1)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End With
If target.Column = 1 Or target.Column = 8 Then
If target.Column = 1 Then
Columns("A").AutoFit
If Columns("A").ColumnWidth < 39 Then
Columns("A").ColumnWidth = 39
End If
Else
Columns("H").AutoFit
If Columns("H").ColumnWidth < 39 Then
Columns("H").ColumnWidth = 39
End If
End If
End If
If target.Column = 5 Or target.Column = 6 Then
If target.Column = 5 Then
groupshed = target.Value
strGrpName = target.Offset(0, -4).Value
Else
grouprows = target.Value
strGrpName = target.Offset(0, -5).Value
End If
If groupshed <> "" And grouprows <> "" Then
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please Wait While Data is Updated..."
Set objGroupConn = New ADODB.Connection
Set objGUpdateCmd = New ADODB.Command
objGroupConn.ConnectionString = "Driver={SQL Server};Server=POSSERVER\GAMPOS;Database=GAM001;User ID=sa;Password=superior2u;"
objGroupConn.Open
Set objGUpdateCmd.ActiveConnection = objGroupConn
objGUpdateCmd.CommandText = "UPDATE dbo.tblgroups SET ShedAssignment = '" & groupshed & "', ShedRow = '" & grouprows & "'" _
& " WHERE((dbo.tblgroups.Visitdate)= '" & vdate & "' AND InCalendar = 1 And Catered = 0 AND GroupName = '" & strGrpName & "' )"
objGUpdateCmd.CommandType = adCmdText
objGUpdateCmd.Execute
objGroupConn.Close
groupshed = ""
grouprows = ""
strGrpName = ""
Application.StatusBar = False
End If
End If
If target.Column = 11 Or target.Column = 12 Then
If target.Column = 11 Then
catershed = target.Value
strGrpName = target.Offset(0, -3).Value
Else
caterrows = target.Value
strGrpName = target.Offset(0, -4).Value
End If
If catershed <> "" And caterrows <> "" Then
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please Wait While Data is Updated..."
Set objGroupConn = New ADODB.Connection
Set objGUpdateCmd = New ADODB.Command
objGroupConn.ConnectionString = "Driver={SQL Server};Server=POSSERVER\GAMPOS;Database=GAM001;User ID=sa;Password=superior2u;"
objGroupConn.Open
Set objGUpdateCmd.ActiveConnection = objGroupConn
objGUpdateCmd.CommandText = "UPDATE dbo.tblgroups SET ShedAssignment = '" & catershed & "', ShedRow = '" & caterrows & "'" _
& " WHERE((dbo.tblgroups.Visitdate)= '" & vdate & "' AND InCalendar = 1 AND Catered = 1 AND GroupName = '" & strGrpName & "' )"
objGUpdateCmd.CommandType = adCmdText
objGUpdateCmd.Execute
objGroupConn.Close
catershed = ""
caterrows = ""
strGrpName = ""
Application.StatusBar = False
End If
End If
Application.EnableEvents = True
End If
End Sub
The issue now is using this same code for all 100 sheets in the workbook.  I tried creating a method in ThisWorkbook...
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
End Sub
...with the code from the first block pasted in.  I am getting a variable not defined error at my SET statements.
I would rather not have to copy all this code to each worksheet if at all possible.  Any thoughts?

Prefix all occurrences of Range and Columns with Sh. to specify that the range and columns belong to the sheet that caused the event. For example:
If Intersect(target, Sh.Range("A4:B39",
"H4:I25")) Is
Nothing Or target.Cells.Count
> 1 Then
Exit Sub
and
If Sh.Columns("E").ColumnWidth
<> 6 Then
Regards, Hans Vogelaar (http://www.eileenslounge.com)

Similar Messages

  • Custom CSS-Applying selected background for all the cols in the report

    Hi,
    I am trying to set a particular background for all the columns in the report(not for all the projects,so that I can avoid option of manually setting background color for complete report.For this I thought custom CSS is best option.So edited custom.css(C:\OBI11g_Middleware\Oracle_BI1\bifoundation\web\app\res\s_blafp\b_mozilla_4) file with below code and went to the Answers-> Criteria->Choose Column->style-> check "Use Custom CSS Class"->MyCell
    Code used in custom.css
    .MyCell { background-color: #00ff00; font-style:italic; font-weight: bold;}
    Somehow I dont see the background color applied to any of the columns in report.Can anyone had successful attempt of this Custom CSS.Thanks in Advance.

    I am trying both the solutions.
    User 979493,
    I started manually writing the code instead of pasting and almost worked.In the mentioned below paths I dont have custom.css file,so I created one and manually entered below code.But does it work for only that particular column and not for all the columns.Is it supposed to work for all the columns or just that column.
    For example: I have 2 cols in the report,I used "Use Custom CSS Class" -> MyCell for the first column and when I ran results it shows background color for only col1 and not for col2.I thought this feature will apply background color for all the columns in the report.Please correct me if I am wrong.
    custom.css file content:
    .MyCell{background-color: #00ff00;font-style:italic;font-weight:bold;}

  • Script set to auto apply Retention policy to all new mailbox created and run everyday

      Script to set auto apply Retention policy to all new mailbox created and run everyday on Exchange 2007 , 2010 , and 2013.
     Could you please help me with the script will rename the policy name please help me with script..
     Thanks,
     Chandu

    Hi Chandu,
    Have you find the solution finally? Have you tried Pavan's suggestion?
    Sorry for my lacking of code and script. If your requirement still haven't been achieved, I suggest we can ask a question in Exchange Development forum and Script Center for more professional suggestion:
    Microsoft Exchange Development forum
    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads
    Script Center
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    Regards,
    Winnie Liang
    TechNet Community Support

  • I have a an iMac 27" and am trying to import some videos of a friends wedding into iMovie however one of the movies won't import. It doesn't say why or give any error message or codes. All of the other movies on the card download with out a problem.

    I have an iMac 27" and am trying to import some videos of a friends wedding into iMovie however one of the movies won't import. It doesn't say why or give any error message or codes.
    All of the other movies on the card download with out a problem. The movie in question is not 'corrupt' as you can watch it in iMovie direct from the SD card but as soon as you try to import it, it  just says 'error'. iIve tried moving the file to an external drive ( and other variations on this theme) then importing but have had no luck.
    Can anyone please help me.

    The mystery remains....
    Thanks for the pointers. The file type is .mts (a proprietry sony one).
    I have now found some video converter software (Wondershare and iSkysoft) at a cost. Either will convert this file for me into .mp4. This I can then import into iMovie without any problems. I've checked this on the trial versions and it worked well but without paying am left with a giant watermark in the video
    The mystery (which I still havent solved) is why did 20 other .mts files import fine and then this one not?
    If you could point me in the direction of some free .mts converter software that would be the cherry on the cake.
    Thanks

  • Applying Tax code on document total as a whole.

    will it be possible to apply tax on a document total as a whole?
    for eg.
    I want to generate a purchase order for 3 items and doesn't want to apply tax code on line level.
    The document total will be say 5000 now i want to put tax code on this value.
    will it be possible.

    Hi,
    In SAP B1, You should link the Tax codes in row level (ie., for every item it's tax code should be defined in that row itself). We cannot define or calculate the tax amount for overall amount.
    Raja.S

  • Remove Company Code with all the Employees in it from r/3?

    Hi i have a bit unusual requirement.
    i want to know how can i Remove a Company Code with all its assigned Employees completely from a system(r/3) ?
    can this be possible at all? if yes then please also mentions what can be the side effects of this action.

    Jack,
    You will have to follow reverse engineering....
    As Sikandar Guru Mentioned.....identify all the PERNRs for mass deletion....
    Secondly I believe, that you want to Delete the Company Code.....check with Finance Folks.......If they have no issues, you can delete the co. code with TCODE EC01... but this will not delete the Relationships to Personnel area...etc.
    There may be custom Features, Reports or programs functioning based on Co. Code.......
    So, in a way....its not feasible..neither wise to attempt deletion of Co. Code....
    S_PHO_48000106 is the TCode for Mass Deletion.
    Good Luck !!!
    Kumarpal Jain.
    Edited by: Kumarpal Jain on Oct 26, 2009 3:20 PM

  • How do I find my old keys, if I didnt register products,and the bar code is all thats left from school purchase?

    How do I find my old Keys, If I didnt register products, and the bar code is all thats left from school?

    Well, then you are SOL.
    Mylenium

  • How will get the source code of all the tables in a given schema using SQL?

    Hi All,
    How can we get the source code of all the tables in a given schema using SQL?
    Thanks in Adv.
    Junu

    Try something like...
    set heading off
    set pagesize 0
    col meta_data for a96 word_wrapped
    set long 100000
    SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) ||';' AS meta_data
    FROM dba_objects
    WHERE owner = '<SCHEMA NAME>'
      AND object_type not in (<list of stuff you do not want>);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to apply source code

    Does Contribute allow Admins to paste in (apply) source code
    to various Web pages? I've got a source code from Google Analytics
    I want to use for tracking and can't find how to apply it using
    Contribute.

    Use Insert--> HTML Snippet and insert the Google Analytics
    code at the end of the page. I tried in one of my site, it worked
    fine.
    When viewed the page source the GA code was insert here
    <GA code comes here>
    </p>
    <!-- #EndEditable --></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    <!-- InstanceEnd --></html>
    Thanks

  • If I select multiple images to apply a change to all Aperture it does so only with the first selected. Why?

    If I select multiple images to apply a change to all openings it does so only with the first selected. Why?

    You probably have Primary Selection only on.
    Aperture identifies the images you’ve selected by displaying them with a white border. When you select a group of images, the actively selected image, called the primary selection, appears with a thick white border and the rest of the selected images appear with thin white borders.
    Primary Only button: Click this button to make changes to the primary image selection only.

  • Macbook pro numbers applying a formula to all rows

    macbook pro, numbers: applying a formula to all rows...
    I am trying to apply the same formula to successive row in a spreadsheet that I am using...how do I go about this?

    Apologies for not replying immediately! I have now managed to organise my entire stock list for my business; I just had a major brain blockage as to how to copy and paste formulae in columns, added to which I've never had any formal training in IT.  I'm not too old to try and have a can do attitude and so far I managed ok. Now I've started my own business I'm putting what I've taught myself in to practice and I'm pleasantly surprising myself with the results.
    Thank you again for your help,
    Regards....charlie.

  • Applying Style Sheets to all Project Topics

    Currently I have topics that use different style sheets (there are 5 listed, although I only created one).
    I want all topics to use the same style sheet.
    Is there any way to apply a Style to all Project Topics?

    Welcome to the forum.
    Go to the topic list and select all topics, then right click and select Properties. You can assign the new CSS there. Any style names in your topics not included in the new CSS will of course be broken and need to be assigned to whatever style you choose.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • I dw file.dwt files may insert server side code supposed all pages depended are in the same code eg

    I dw file.dwt (exact like this ext) files may insert server side code supposed all pages depended are in the same code eg cfml?

    I'm sorry, but your English is pretty difficult for me to figure.  I'm assuming your asking how to have a Dreameraver template support ColdFusion. It hat is what you are asking, the template file extension should be:  YourTemplateName.dwt.cfm  - this tells Dreamweaver is a ColdFusion template.
    I hope I understood you and that this helps.
    Lawrence Cramer - *Adobe Community Professional*
    http://www.Cartweaver.com
    Shopping Cart for Adobe Dreamweaver
    available in PHP, ColdFusion, and ASP
    Stay updated - http://blog.cartweaver.com

  • How to view code of all the custom and complex folder  folder

    How to view code of all the custom and complex folder folder in EUL?

    You do not need to run all the reports.
    Also i am not sure about why do you need to see the code of every thing, i assume you will not get much from it.
    If there is a certain folder you are interested in then this is the way.
    Any way there is no way to get the code of the complex folders since they are logical join of other folders.
    to get the code of the custom folder s you can use:
    select * from eul_us.eul5_objs t
    WHERE t.obj_type='CUO'
    AND t.obj_object_sql1 IS NOT NULL;
    you should look (and concatenate) at the obj_object_sql1,obj_object_sql2.....
    Tamir

  • Adding One Line Code in all tables in Designer Trigger.

    I have 300+ tables in my Schema (All tables generated through Designer), I want to add one line of code in the begining of "Before Inset Row Trigger" of all tables, So what is the fastest way of doing that,
    Adding One Line Code in all tables in Designer Trigger.
    I don't want to go and modify each and every table

    You'll have to write a script that reads out the current contents of your triggers, add your line to this contents and dynamically "create or replace" the new trigger text.
    Beware, trigger_body column of user/all/dba_triggers is in a column with datatype LONG, so you'll have to use some sort of conversion.
    Good luck.
    regards,
    Rob.

Maybe you are looking for

  • 2nd Display Help

    Is it possible if i've got my macbook hooked up to an external display to have the external display as my primary display and then treat the macbook display as the secondary one so the taskbar and dock are on the external. I've searched around but ca

  • "CPU Fan has failed"

    I keep getting this message when I turn on my pc. It says "Fan CPU has failed.  Your computer will shut down" and then it shuts off. Sometimes I get it once a week and then sometimes it goes 2 weeks before it happens.  How do I fix this problem? My p

  • HP Solution Center device installati​on not complete

    I have a PhotoSmart C7280 all-in-one printer running as an Ethernet networked printer.  My personal PC is an HP Pavilion Slimline s5280t running Windows 7 Pro 64 bit.  I've had the printer for longer than I've had the Pavilion.  I use HP Solution Cen

  • Help on Configuration of Schedule Line agreement

    Hi friends please let  me to know the configuration steps of Schedule Line agreement Thanks for ur help Regards Krishna

  • Network icon disappeared

    Under system preferences "network" "bluetooth" and "sharing" have disappeared. I am no longer able to get online. 15 years of using macs, this has never happened. Please help. Thanks