Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default how to use select case

Hi,

Pls see my example of the macro that i did. My intention is to find in
column G, cells that has either values of "AS", "HC" or "50", if found , then
for column P in the same row, it will return that value. But it does not
work. i tried to use selection.find but i cannot multi find, so i use
select...case instead.

Can anyone advise my mistake in my macro below?
e.g.

Sub Testing()

Dim Result As String
Dim CheckVal As String

Range("A1").Select
NumOfRows = Cells(Rows.Count, "1").End(xlUp).Row

CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

Select Case UCase(CheckVal)
Case "AS"
Result = "AS"
Case "50"
Result = "50"
Case "HC"
Result = "HC"

Case Else
Result = "" 'equals to blank

End Select

Next
MsgBox ("Done!!!Thanks for Playing!!!")

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to use select case

Hi Junior,

Perhaps try something like:

'=============
Public Sub Testing()
Dim CheckVal As String
Dim NumOfRows As Long
Dim CurrentRow As Long

NumOfRows = Cells(Rows.Count, 1).End(xlUp).Row
For CurrentRow = 1 To NumOfRows
CheckVal = ActiveSheet.Cells(CurrentRow, 7).Value
With ActiveSheet.Cells(CurrentRow, 7)
Select Case UCase(CheckVal)
Case "AS", "SO", "HC"
'Do nothing
Case Else
.Value = ""
End Select
End With
Next CurrentRow
MsgBox ("Done!!!Thanks for Playing!!!")
End Sub
'<<=============


---
Regards,
Norman


"Junior728" wrote in message
...
Hi,

Pls see my example of the macro that i did. My intention is to find in
column G, cells that has either values of "AS", "HC" or "50", if found ,
then
for column P in the same row, it will return that value. But it does not
work. i tried to use selection.find but i cannot multi find, so i use
select...case instead.

Can anyone advise my mistake in my macro below?
e.g.

Sub Testing()

Dim Result As String
Dim CheckVal As String

Range("A1").Select
NumOfRows = Cells(Rows.Count, "1").End(xlUp).Row

CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

Select Case UCase(CheckVal)
Case "AS"
Result = "AS"
Case "50"
Result = "50"
Case "HC"
Result = "HC"

Case Else
Result = "" 'equals to blank

End Select

Next
MsgBox ("Done!!!Thanks for Playing!!!")

End Sub






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default how to use select case

Your mistake is CheckVal and Results need to be inside the "For loop'. both
equations use CurrentRow.

From:
CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

to:
For CurrentRow = 1 To NumOfRows
CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

"Junior728" wrote:

Hi,

Pls see my example of the macro that i did. My intention is to find in
column G, cells that has either values of "AS", "HC" or "50", if found , then
for column P in the same row, it will return that value. But it does not
work. i tried to use selection.find but i cannot multi find, so i use
select...case instead.

Can anyone advise my mistake in my macro below?
e.g.

Sub Testing()

Dim Result As String
Dim CheckVal As String

Range("A1").Select
NumOfRows = Cells(Rows.Count, "1").End(xlUp).Row

CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

Select Case UCase(CheckVal)
Case "AS"
Result = "AS"
Case "50"
Result = "50"
Case "HC"
Result = "HC"

Case Else
Result = "" 'equals to blank

End Select

Next
MsgBox ("Done!!!Thanks for Playing!!!")

End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default how to use select case


Case "AS", "HC", 50: Cells(i, "h") = Cells(i, "p")
should be

Case "AS", "HC", 50: Cells(i, "P") = Cells(i, "G")

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
IF?? I understand what you want.
Sub findtest()
For i = 1 To Cells(Rows.Count, "g").End(xlUp).row
Select Case UCase(Cells(i, "g"))
Case "AS", "HC", 50: Cells(i, "h") = Cells(i, "p")
Case Else
End Select
Next i
End Sub


--
Don Guillett
SalesAid Software

"Junior728" wrote in message
...
Hi,

Pls see my example of the macro that i did. My intention is to find in
column G, cells that has either values of "AS", "HC" or "50", if found ,
then
for column P in the same row, it will return that value. But it does not
work. i tried to use selection.find but i cannot multi find, so i use
select...case instead.

Can anyone advise my mistake in my macro below?
e.g.

Sub Testing()

Dim Result As String
Dim CheckVal As String

Range("A1").Select
NumOfRows = Cells(Rows.Count, "1").End(xlUp).Row

CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

Select Case UCase(CheckVal)
Case "AS"
Result = "AS"
Case "50"
Result = "50"
Case "HC"
Result = "HC"

Case Else
Result = "" 'equals to blank

End Select

Next
MsgBox ("Done!!!Thanks for Playing!!!")

End Sub








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default how to use select case

Hi All,

It works perfectly...thank you all...=)

"Junior728" wrote:

Hi,

Pls see my example of the macro that i did. My intention is to find in
column G, cells that has either values of "AS", "HC" or "50", if found , then
for column P in the same row, it will return that value. But it does not
work. i tried to use selection.find but i cannot multi find, so i use
select...case instead.

Can anyone advise my mistake in my macro below?
e.g.

Sub Testing()

Dim Result As String
Dim CheckVal As String

Range("A1").Select
NumOfRows = Cells(Rows.Count, "1").End(xlUp).Row

CheckVal = ActiveSheet.Cells(CurrentRow, 7) 'Column G
Result = ActiveSheet.Cells(CurrentRow, 16) 'Column P

For CurrentRow = 1 To NumOfRows

Select Case UCase(CheckVal)
Case "AS"
Result = "AS"
Case "50"
Result = "50"
Case "HC"
Result = "HC"

Case Else
Result = "" 'equals to blank

End Select

Next
MsgBox ("Done!!!Thanks for Playing!!!")

End Sub




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
select case in vba Hein Excel Discussion (Misc queries) 5 November 25th 09 07:28 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
For Each with Select Case helmekki[_30_] Excel Programming 0 October 15th 04 03:36 AM


All times are GMT +1. The time now is 12:59 PM.

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

About Us

"It's about Microsoft Excel"