• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Case Statement Question

chirayu

Well-Known Member
Hi All,

This is with regards to the below Case Statement

Code:
Select Case ActiveCell.Value
Case "Site1", "Site3", "Site9"
Rows(ActiveCell.Row).Select
Selection.Delete
ActiveCell.Offset(0, 1).Select
Case Else
ActiveCell.Offset(1, 0).Select
End Select
Loop

Currently under the case argument I have specified my values i.e. Site1/Site3/Site9.

Is it possible instead to use a given range in the macro so that I don't need to keep manually typing in my values in the macro itself whenever change is needed? e.g.

Code:
Worksheets("Sheet1").Range("A1:A3").Value
 
Code:
Dim findRange As Range, rng As Range
    Set findRange = Worksheets("Sheet1").Range("A1:A3")
   
    Set rng = findRange.Find(ActiveCell.Value, LookAt:=xlWhole)
    If Not rng Is Nothing Then
        Rows(ActiveCell.Row).Select
        Selection.Delete
        ActiveCell.Offset(0, 1).Select
    Else
        ActiveCell.Offset(1, 0).Select
    End If
 
If there are multiple actions and combinations then usage of Select is good. In above case, If...else construct would also do fine.
Code:
Select Case IsNumeric(Application.Match(ActiveCell.Value, Sheets("Sheet1").Range("A1:A3").Value, 0))
Case True
  Rows(ActiveCell.Row).Select
  Selection.Delete
  ActiveCell.Offset(0, 1).Select
Case Else
  ActiveCell.Offset(1, 0).Select
End Select
 
Back
Top