none
How to check the cell name in excel RRS feed

  • Question

  • Hi all,

    First, my english is bad..IF anything not clear, please remind me. Thnx.

    I had following screensnap:

    I want to write a coding to check if the cell in the menu is contain 20V then will proceed to next step.

    Because the different between 2 pic is 20V and 40V.

    Can anyone show me some coding? thnx.

    Tuesday, October 11, 2011 5:43 AM

Answers

  • You might try this:

    Sub Test()
    
    Dim ws As Worksheet
    Dim rng As Range
    
    Set ws = Sheets("CGP_Menu")
        Set rng = ws.Range("C11")
        Do Until IsEmpty(rng)
            If InStr(rng.Text, "_20V_") > 0 Then
                'Have a 20V cell
            End If
            Set rng = rng.Offset(1, 0)
        Loop
        
    Set ws = Nothing
    
    End Sub
    


    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, January 31, 2012 1:02 AM
    Moderator

All replies

  • Sub Test()
    Dim rng As Range
        Set rng = Range("C11")
        Do Until IsEmpty(rng)
            If InStr(rng.Text, "_20V_") > 0 Then
                'Have a 20V cell
            End If
            Set rng = rng.Offset(1, 0)
        Loop
    End Sub


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Tuesday, October 11, 2011 7:30 AM
  • Thank you for your reply.

    If i want to set as selected sheet range?

    Like above is CGP_Menu.

    Then i should dim rng as ?

    Wednesday, October 12, 2011 8:07 AM
  • You might try this:

    Sub Test()
    
    Dim ws As Worksheet
    Dim rng As Range
    
    Set ws = Sheets("CGP_Menu")
        Set rng = ws.Range("C11")
        Do Until IsEmpty(rng)
            If InStr(rng.Text, "_20V_") > 0 Then
                'Have a 20V cell
            End If
            Set rng = rng.Offset(1, 0)
        Loop
        
    Set ws = Nothing
    
    End Sub
    


    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, January 31, 2012 1:02 AM
    Moderator