LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Select Case

Yes Dave, it is still going to the right 2 places.

Thank you Dave and Jim for all your help. Not only have you answered my
problem, but you taught me too!

"Dave Peterson" wrote:

Maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub 'one cell at a time

If Intersect(Target, Me.Range("B2:B100,E2:E100,H2:H100,K2:K100," _
& "N2:N100,Q2:Q100,T2:T100")) Is Nothing Then
Exit Sub
End If

Select Case UCase(Target.Value)
Case "A", "H", "V"
Target.Offset(0, 2).Value = 8
Case Else
Target.Offset(0, 2).FormulaR1C1 _
= "=IF(COUNT(RC[-2]:RC[-1])=2,(RC[-1]-RC[-2])*24-0.5,0)"
'MsgBox "Not A, H or V."
End Select

End Sub

I'm not sure what happens to the formula, though--is it still going in the cell
two to the right?

MikeG wrote:

That worked great! How about one more request. Right now, this works for
column B. What if I wanted it to aslo work for columns E, H, K, N, Q and T
for the rest of the week. Can this be done?

Thanks!

"Dave Peterson" wrote:

Maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("B2:B100")) Is Nothing Then
Select Case UCase(Target.Value)
Case "A", "H", "V"
Target.Offset(0, 2).Value = 8
Case Else
Target.Offset(0, 2).FormulaR1C1 _
= "=IF(COUNT(RC[-2]:RC[-1])=2,(RC[-1]-RC[-2])*24-0.5,0)"
'MsgBox "Not A, H or V."
End Select
End If
End Sub


MikeG wrote:

The code works great except it removes a calculation for finding hours worked:
=IF(COUNT(B8:C8)=2,(C8-B8)*24-0.5,0)

Can the line after Case Else MsgBox "Not A, H, or V." be replaced with this
formula so that the calculation will take place if A, H, or V are not
selected?

Thanks!

"Jim Thomlinson" wrote:

Sure if you want the code to work you can do that but I thought that this was
much more inventive... ;-) Thanks for catching that one...
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

I think that this:
If not intersect (Target.Column, Range("B2:B100") is nothing Then
should be:
If not intersect (Target, Range("B2:B100")) is nothing Then

Target.column will return a number (and a typo missing that final close
parenthesis).

Jim Thomlinson wrote:

here it is for changed made to B2 through B100, updating column D... This
should be a bit closer...

Private Sub Worksheet_Change(ByVal Target As Range)
If not intersect (Target.Column, Range("B2:B100") is nothing Then
Select Case UCase(Target.Value)
Case "A", "H", "V"
Target.Offset(0, 2).Value = 8
Case Else
MsgBox "Not A, H or V."
End Select
End If
End Sub

--
HTH...

Jim Thomlinson

"MikeG" wrote:

Can this be edited so that the Target is a range of cells rather than a column?

"Jim Thomlinson" wrote:

Your description is a little thin. Here is some event code that responds to
changes in column A and places a value beside the cell that was changed.
Right click the sheet tab and select view code. Paste the following...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Select Case UCase(Target.Value)
Case "A", "H", "V"
Target.Offset(0, 1).Value = 8
Case Else
MsgBox "Not A, H or V."
End Select
End If
End Sub
--
HTH...

Jim Thomlinson


"MikeG" wrote:

I would like to be able to enter the letters "V", "H" or "A" into a cell and
have the number 8 entered into another cell. How can this be done using
Select Case?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

 
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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Select Case Jeff Excel Discussion (Misc queries) 1 February 27th 06 02:56 PM
Select Case help Ramthebuffs[_14_] Excel Programming 4 October 13th 05 12:41 AM
Select case Sandy[_6_] Excel Programming 2 July 3rd 05 09:23 PM


All times are GMT +1. The time now is 02:50 AM.

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"