Consulting

Results 1 to 4 of 4

Thread: Loop Case Statement

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Loop Case Statement

    I have a spreadsheet that I would like to look at Column A and grab first and last row as a range.
    Then I need for it to loop through that range and based on each cell in range put a value in Column H in same row.
    So it select case first cell in range and return it's case value to H, then go to next cell in range and continue until it's done with range.
    Any help would be great.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something along the lines of

    For i = 2 To Range("A2").End(xlDown).Row
    
        If Cells(i, "A").Value = somevalue Then
    
            Cells(i, "H").Value Cells(i, "A").Value
        End If
    Next i
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Sub M_snb()
      UsedRange.Columns(1).Offset(, 7) = UsedRange.Columns(1).Value
    End Sub

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    For each Cel in UsedRange.Columns(1)
       Select Case Cel
          Case 1: Range("H" & CStr(Cel.Row)).Value = "Answer1"
       End Select
    Next Cel
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •