Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Problem with setting value in validated range

Excel 2007

I'm having a problem with datavalidation in VBA.

I have a couple of cells (Ranges: "Stress_health" and "Stress_Composure")
which contain values in the wingdings font - so they value might be
"jjjjj", for instance.
So, to esnure these don't have to be typed in, I've created a range on
another sheet which contains the possible valid character values.
The complication is that sometimes the list exposed to the user changes,
so it's sometimes "List_Stress1", or "List_Stress2" or "List_Stress3"

So what the Sub below is supposed to do, is check the Stess_Health or
Stress_Composure box for which of the three lists is in use, then enter a
value from that list.

The Stress_Health and Stress_Composure boxes are merged cells, each 1 row
x 9 columns.

When this macro runs, it does nothing. The last row of the subroutine
"StressBoxes" should change the cell, but nothing happens. Even stranger,
if I happen to have any code after this point, it doesn't run but no error
is reported.
It doesn't seem to be related to the merged cells, since the same thing
happens if I unmerge the cells and use the commented out line.

I've been struggling with this off and on for about a week, and getting
nowhere. Any ideas?

Thanks,
Darren

Function GetValidationRange(ByVal CheckRange As Range) As String
Dim DataValid As String
DataValid = CheckRange.Validation.Formula1
DataValid = Replace(DataValid, "=", "")
GetValidationRange = DataValid
End Function

Sub StressBoxes(mySheet As Worksheet, bHealthOrComposure As Boolean,
myValue As Integer)

Dim StressText As String
Dim HealthOrComp As String
Dim rgRow As Integer
Dim ValidRange As String
Dim myRange As Range

Select Case bHealthOrComposure
Case True
HealthOrComp = "Stress_Health"
Case False
HealthOrComp = "Stress_Composure"
Case Else
' do nothing and end the procedure
Exit Sub
End Select

ValidRange = GetValidationRange(mySheet.Range(HealthOrComp))

Select Case myValue
Case 0
rgRow = 0
Case 1
rgRow = 1
Case 2, 3
rgRow = 2
Case 4, 5
rgRow = 3
End Select

Set myRange = Range(ValidRange)
StressText = myRange.Offset(rgRow, 0).Resize(1, 1).Value
'mySheet.Range(HealthOrComp).Value = StressText
mySheet.Range(HealthOrComp).MergeArea.Cells(1, 1).Value = StressText
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Problem with setting value in validated range

How is "StressBoxes" being called? You're certain it's even running ?

Have you tried inserting some debug statements or stepping through the
procedure line-by-line to see what's happening ?

Tim

"Darren Hill" wrote in message
...
Excel 2007

I'm having a problem with datavalidation in VBA.

I have a couple of cells (Ranges: "Stress_health" and "Stress_Composure")
which contain values in the wingdings font - so they value might be
"jjjjj", for instance.
So, to esnure these don't have to be typed in, I've created a range on
another sheet which contains the possible valid character values.
The complication is that sometimes the list exposed to the user changes,
so it's sometimes "List_Stress1", or "List_Stress2" or "List_Stress3"

So what the Sub below is supposed to do, is check the Stess_Health or
Stress_Composure box for which of the three lists is in use, then enter a
value from that list.

The Stress_Health and Stress_Composure boxes are merged cells, each 1 row
x 9 columns.

When this macro runs, it does nothing. The last row of the subroutine
"StressBoxes" should change the cell, but nothing happens. Even stranger,
if I happen to have any code after this point, it doesn't run but no error
is reported.
It doesn't seem to be related to the merged cells, since the same thing
happens if I unmerge the cells and use the commented out line.

I've been struggling with this off and on for about a week, and getting
nowhere. Any ideas?

Thanks,
Darren

Function GetValidationRange(ByVal CheckRange As Range) As String
Dim DataValid As String
DataValid = CheckRange.Validation.Formula1
DataValid = Replace(DataValid, "=", "")
GetValidationRange = DataValid
End Function

Sub StressBoxes(mySheet As Worksheet, bHealthOrComposure As Boolean,
myValue As Integer)

Dim StressText As String
Dim HealthOrComp As String
Dim rgRow As Integer
Dim ValidRange As String
Dim myRange As Range

Select Case bHealthOrComposure
Case True
HealthOrComp = "Stress_Health"
Case False
HealthOrComp = "Stress_Composure"
Case Else
' do nothing and end the procedure
Exit Sub
End Select

ValidRange = GetValidationRange(mySheet.Range(HealthOrComp))

Select Case myValue
Case 0
rgRow = 0
Case 1
rgRow = 1
Case 2, 3
rgRow = 2
Case 4, 5
rgRow = 3
End Select

Set myRange = Range(ValidRange)
StressText = myRange.Offset(rgRow, 0).Resize(1, 1).Value
'mySheet.Range(HealthOrComp).Value = StressText
mySheet.Range(HealthOrComp).MergeArea.Cells(1, 1).Value = StressText
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Problem with setting value in validated range

Stressboxes is called by the worksheet_change event, and I've stepped
through it line by line, watching it in increasing baflement as everything
seems to be working correctly up until that last line when nothing happens
(or, when I've put code after it, like a msgbox statement, see the macro
stop with no error before that new code is reached).


On Sat, 23 Jun 2007 19:09:23 +0100, Tim Williams <timjwilliams at gmail
dot <"com" wrote:

How is "StressBoxes" being called? You're certain it's even running ?

Have you tried inserting some debug statements or stepping through the
procedure line-by-line to see what's happening ?

Tim

"Darren Hill" wrote in message
...
Excel 2007

I'm having a problem with datavalidation in VBA.

I have a couple of cells (Ranges: "Stress_health" and "Stress_Composure")
which contain values in the wingdings font - so they value might be
"jjjjj", for instance.
So, to esnure these don't have to be typed in, I've created a range on
another sheet which contains the possible valid character values.
The complication is that sometimes the list exposed to the user changes,
so it's sometimes "List_Stress1", or "List_Stress2" or "List_Stress3"

So what the Sub below is supposed to do, is check the Stess_Health or
Stress_Composure box for which of the three lists is in use, then enter a
value from that list.

The Stress_Health and Stress_Composure boxes are merged cells, each 1 row
x 9 columns.

When this macro runs, it does nothing. The last row of the subroutine
"StressBoxes" should change the cell, but nothing happens. Even stranger,
if I happen to have any code after this point, it doesn't run but no
error
is reported.
It doesn't seem to be related to the merged cells, since the same thing
happens if I unmerge the cells and use the commented out line.

I've been struggling with this off and on for about a week, and getting
nowhere. Any ideas?

Thanks,
Darren

Function GetValidationRange(ByVal CheckRange As Range) As String
Dim DataValid As String
DataValid = CheckRange.Validation.Formula1
DataValid = Replace(DataValid, "=", "")
GetValidationRange = DataValid
End Function

Sub StressBoxes(mySheet As Worksheet, bHealthOrComposure As Boolean,
myValue As Integer)

Dim StressText As String
Dim HealthOrComp As String
Dim rgRow As Integer
Dim ValidRange As String
Dim myRange As Range

Select Case bHealthOrComposure
Case True
HealthOrComp = "Stress_Health"
Case False
HealthOrComp = "Stress_Composure"
Case Else
' do nothing and end the procedure
Exit Sub
End Select

ValidRange = GetValidationRange(mySheet.Range(HealthOrComp))

Select Case myValue
Case 0
rgRow = 0
Case 1
rgRow = 1
Case 2, 3
rgRow = 2
Case 4, 5
rgRow = 3
End Select

Set myRange = Range(ValidRange)
StressText = myRange.Offset(rgRow, 0).Resize(1, 1).Value
'mySheet.Range(HealthOrComp).Value = StressText
mySheet.Range(HealthOrComp).MergeArea.Cells(1, 1).Value = StressText
End Sub





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Problem with setting value in validated range

Here's the code from the worksheet_change event:

If Not Application.Intersect(Target, Range("Skills")) Is Nothing Then
If blCancel Then Exit Sub
blCancel = True
SkillsChange Target.Worksheet
blCancel = False
End If

And here's the SkillsChange macro.

Sub SkillsChange(ws As Worksheet)
' need a macro to check if a skill changed, and update any values based on
it.
' doesn't need to use the "Target" variable, just recalculate the various
bits needed.

Dim CharName As String
Dim EnduranceRank As Integer
Dim ResolveRank As Integer

CharName = ws.Range("CharName").Value
' health stress
EnduranceRank = FindTraitValue(FindTraitRank("Endurance", CharName))
' composure stress
ResolveRank = FindTraitValue(FindTraitRank("Resolve", CharName))

Call StressBoxes(ws, True, EnduranceRank)
Call StressBoxes(ws, False, ResolveRank)

' initiative ratings


End Sub

The FindTraitValue and FindTraitRank functions work properly - I use them
in the worksheet for other things. Basically, they return a number from 0
to 5.


On Sat, 23 Jun 2007 19:09:23 +0100, Tim Williams <timjwilliams at gmail
dot <"com" wrote:

How is "StressBoxes" being called? You're certain it's even running ?

Have you tried inserting some debug statements or stepping through the
procedure line-by-line to see what's happening ?

Tim

"Darren Hill" wrote in message
...
Excel 2007

I'm having a problem with datavalidation in VBA.

I have a couple of cells (Ranges: "Stress_health" and "Stress_Composure")
which contain values in the wingdings font - so they value might be
"jjjjj", for instance.
So, to esnure these don't have to be typed in, I've created a range on
another sheet which contains the possible valid character values.
The complication is that sometimes the list exposed to the user changes,
so it's sometimes "List_Stress1", or "List_Stress2" or "List_Stress3"

So what the Sub below is supposed to do, is check the Stess_Health or
Stress_Composure box for which of the three lists is in use, then enter a
value from that list.

The Stress_Health and Stress_Composure boxes are merged cells, each 1 row
x 9 columns.

When this macro runs, it does nothing. The last row of the subroutine
"StressBoxes" should change the cell, but nothing happens. Even stranger,
if I happen to have any code after this point, it doesn't run but no
error
is reported.
It doesn't seem to be related to the merged cells, since the same thing
happens if I unmerge the cells and use the commented out line.

I've been struggling with this off and on for about a week, and getting
nowhere. Any ideas?

Thanks,
Darren

Function GetValidationRange(ByVal CheckRange As Range) As String
Dim DataValid As String
DataValid = CheckRange.Validation.Formula1
DataValid = Replace(DataValid, "=", "")
GetValidationRange = DataValid
End Function

Sub StressBoxes(mySheet As Worksheet, bHealthOrComposure As Boolean,
myValue As Integer)

Dim StressText As String
Dim HealthOrComp As String
Dim rgRow As Integer
Dim ValidRange As String
Dim myRange As Range

Select Case bHealthOrComposure
Case True
HealthOrComp = "Stress_Health"
Case False
HealthOrComp = "Stress_Composure"
Case Else
' do nothing and end the procedure
Exit Sub
End Select

ValidRange = GetValidationRange(mySheet.Range(HealthOrComp))

Select Case myValue
Case 0
rgRow = 0
Case 1
rgRow = 1
Case 2, 3
rgRow = 2
Case 4, 5
rgRow = 3
End Select

Set myRange = Range(ValidRange)
StressText = myRange.Offset(rgRow, 0).Resize(1, 1).Value
'mySheet.Range(HealthOrComp).Value = StressText
mySheet.Range(HealthOrComp).MergeArea.Cells(1, 1).Value = StressText
End Sub





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
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
problem setting the used range for a column Janis Excel Discussion (Misc queries) 2 January 17th 08 01:04 PM
how do i prevent duplicate values in a range of validated cells? scw Excel Discussion (Misc queries) 1 December 20th 06 09:43 AM
How do I prevent duplicate numbers in a range of validated cells? [email protected] Charts and Charting in Excel 0 December 20th 06 07:47 AM
Problem setting SeriesCollections source range Lead Foot Charts and Charting in Excel 2 January 27th 06 05:11 AM
Problem setting a range stefantem[_9_] Excel Programming 1 October 19th 04 09:17 AM


All times are GMT +1. The time now is 11:59 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"