Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Workbook VBA not recognising half the new worksheet!!

Hi all,

I have a workbook with some 21 sheets, i have recently added a shee
and copied the code over for it (this part of the vba works fine!
however the code that is in the This workbook module does not seem t
work for this worksheet, i swapped this sheets position with the las
one still no joy and now that i have switched them back the sheet
swapped it with now has the same problem i cant see a fault in m
code......here is the code for the sheet and this workbook module.

Can you help??

Simon

Here's the code

Option Explicit


Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVa
Target As Range)
Dim valstr
Dim fValid As Boolean
Dim valint As Integer

On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, sh.Range("Skills" & sh.Index)) Is Nothin
Then

valstr = InputBox("Enter Skill Level" & vbCrLf & _
Space(5) & "1 = In Training" & vbCrLf & _
Space(5) & "2 = Trained" & vbCrLf & _
Space(5) & "3 = Can Train Others" & vbCrL
& _
Space(5) & "4 = Delete Colour and Entry"
_
"Skills Breakdown and Competencies Entry"
"")
valint = Val(valstr)

If valint = 0 Then

Application.EnableEvents = True
sh.Protect

Exit Sub

End If

With Target
sh.Unprotect

Select Case valint
Case 1: .Interior.ColorIndex = 48
Case 2: .Interior.ColorIndex = 33
Case 3: .Interior.ColorIndex = 6
Case 4: .Interior.ColorIndex = xlNone
.Value = ""

Case Else: MsgBox "Invalid Entry Try Again!"

End Select
If valint = 4 Then
With Target
sh.Cells(.Row, .Column + kTestColOff).Value = ""
End With
Else
CheckCondition Target, sh
End If
'sh.Range("A" & .Row).Select
End With


End If

ws_exit:
Application.EnableEvents = True

End Sub

Private Sub CheckCondition(ByVal Target As Range, ByVal sh As Object)

Dim rngtest As Range

With Target
Set rngtest = sh.Cells(.Row, .Column + kTestColOff)
If rngtest = "" Then
.Font.ColorIndex = kColorTest1
.Value = "h"

End If
rngtest.Value = ""
End With

End Sub

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Object
Dim myrange As Range
Dim ComboBox1
Dim I1 As Integer
Dim res As Variant
Dim arySheets
On Error Resume Next


With arySheets

Set myrange = Range("E3:H641")
If Not Intersect(myrange, Target) Is Nothing Then

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
arySheets = Array("FSP's", "Quality & Others", "Alpha Process"
"Bulk & H&I", _
"Corn Process", "33 Bldg Packing", "Ctd Cor
Packing", _
"2 & 3 Coating", "Crispix", "Feed&Lab"
"Flavour", _
"Jet Zones", "Alpha Packing", "MPD", "Plan
Awareness", _
"Rice Cooking", "Vehicle Drivers (plant)"
"VIP", _
"15-21 & 22", "4&5 Coating", "Tank Floor 15
33 Bldg")

Sheets(arySheets).Select


For Each sh In ActiveWorkbook.Worksheets
sh.Unprotect
Next
End If

If ActiveCell.Column = 5 And ActiveCell.Column <= 8 An
ActiveCell.Row = 3 And ActiveCell.Row <= 641 Then
UserForm1.Show
If Not IsError(res) Then

ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Worksheets("hidden").Visible = False
Me.Select

End If

If ActiveCell < "shift " Then
Range("A" & ActiveCell.Row).Select
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst

End If
End If

End With


End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Workbook VBA not recognising half the new worksheet!!

I didn't spend a lot of time in your code, but your first procedure is
dependent on this if statement:

intersect(Target, sh.Range("Skills" & sh.Index))

so I suspect the new sheets don't have the defined name and when you moved
the other sheet, you changed its index so it no longer corresponded to the
defined name you had defined for that sheet.

--
Regards,
Tom Ogilvy


"Simon Lloyd " wrote in message
...
Hi all,

I have a workbook with some 21 sheets, i have recently added a sheet
and copied the code over for it (this part of the vba works fine!)
however the code that is in the This workbook module does not seem to
work for this worksheet, i swapped this sheets position with the last
one still no joy and now that i have switched them back the sheet i
swapped it with now has the same problem i cant see a fault in my
code......here is the code for the sheet and this workbook module.

Can you help??

Simon

Here's the code

Option Explicit


Private Sub Workbook_SheetSelectionChange(ByVal sh As Object, ByVal
Target As Range)
Dim valstr
Dim fValid As Boolean
Dim valint As Integer

On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, sh.Range("Skills" & sh.Index)) Is Nothing
Then

valstr = InputBox("Enter Skill Level" & vbCrLf & _
Space(5) & "1 = In Training" & vbCrLf & _
Space(5) & "2 = Trained" & vbCrLf & _
Space(5) & "3 = Can Train Others" & vbCrLf
& _
Space(5) & "4 = Delete Colour and Entry",
_
"Skills Breakdown and Competencies Entry",
"")
valint = Val(valstr)

If valint = 0 Then

Application.EnableEvents = True
sh.Protect

Exit Sub

End If

With Target
sh.Unprotect

Select Case valint
Case 1: .Interior.ColorIndex = 48
Case 2: .Interior.ColorIndex = 33
Case 3: .Interior.ColorIndex = 6
Case 4: .Interior.ColorIndex = xlNone
Value = ""

Case Else: MsgBox "Invalid Entry Try Again!"

End Select
If valint = 4 Then
With Target
sh.Cells(.Row, .Column + kTestColOff).Value = ""
End With
Else
CheckCondition Target, sh
End If
'sh.Range("A" & .Row).Select
End With


End If

ws_exit:
Application.EnableEvents = True

End Sub

Private Sub CheckCondition(ByVal Target As Range, ByVal sh As Object)

Dim rngtest As Range

With Target
Set rngtest = sh.Cells(.Row, .Column + kTestColOff)
If rngtest = "" Then
Font.ColorIndex = kColorTest1
Value = "h"

End If
rngtest.Value = ""
End With

End Sub

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Object
Dim myrange As Range
Dim ComboBox1
Dim I1 As Integer
Dim res As Variant
Dim arySheets
On Error Resume Next


With arySheets

Set myrange = Range("E3:H641")
If Not Intersect(myrange, Target) Is Nothing Then

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
arySheets = Array("FSP's", "Quality & Others", "Alpha Process",
"Bulk & H&I", _
"Corn Process", "33 Bldg Packing", "Ctd Corn
Packing", _
"2 & 3 Coating", "Crispix", "Feed&Lab",
"Flavour", _
"Jet Zones", "Alpha Packing", "MPD", "Plant
Awareness", _
"Rice Cooking", "Vehicle Drivers (plant)",
"VIP", _
"15-21 & 22", "4&5 Coating", "Tank Floor 15 &
33 Bldg")

Sheets(arySheets).Select


For Each sh In ActiveWorkbook.Worksheets
sh.Unprotect
Next
End If

If ActiveCell.Column = 5 And ActiveCell.Column <= 8 And
ActiveCell.Row = 3 And ActiveCell.Row <= 641 Then
UserForm1.Show
If Not IsError(res) Then

ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Worksheets("hidden").Visible = False
Me.Select

End If

If ActiveCell < "shift " Then
Range("A" & ActiveCell.Row).Select
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst

End If
End If

End With


End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Workbook VBA not recognising half the new worksheet!!

Well, I unhid the hidden sheet then moved the new sheet to the end
putting the hidden sheet between my original which stopped working and
the new one and hey presto!!! it works.....i have no idea why, as i had
checked that there was a name defined for both intersect areas.

It's a mystery but panic over!.....Tom once again thanks for your
reply.

Simon


---
Message posted from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formatting only working for half of worksheet mmurphy Excel Discussion (Misc queries) 1 December 15th 09 05:53 PM
print half of rows on left and other half on right Steve B. Excel Discussion (Misc queries) 2 November 16th 07 11:20 AM
Can I have the bottom half Worksheet with less columns than Top Toby Excel Discussion (Misc queries) 1 May 19th 07 12:57 PM
On opening workbook - it kinda half closes :-S DS Excel Discussion (Misc queries) 4 February 28th 07 04:31 PM
Workbook only occupies half the window - rest is blank? Senior trying to keep up Excel Discussion (Misc queries) 2 May 14th 05 11:28 PM


All times are GMT +1. The time now is 08:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"