Results 1 to 4 of 4

Excel 2007 : If Then Else and/or Select Case Coding Assistance

Threaded View

  1. #1
    Registered User
    Join Date
    06-29-2012
    Location
    SF
    MS-Off Ver
    Excel 2007
    Posts
    2

    Question If Then Else and/or Select Case Coding Assistance

    So I am trying to get the following If then else statement to work. I believe I am having the most difficulty in getting the embedded loop to loop (the "else" part of the macro)

    I believe the code shows what I am trying to do pretty clearly, which is if a cell in sheet1 equals a cell in sheet 2, make the original sheet 1 cell equal to a cell in sheet 2. the Part I am having trouble with is that if the cell doesn't equal the cell in sheet2, I want it to continue going down the list until it hits the cell for which it is equivalent.

    Sub ReportGen()
    Dim Rrow As Integer
    Dim Rcol As Integer
    Dim Mrow As Integer
    Dim Mcol As Integer
    Dim mNcol As Integer
    
    Mcol = 2
    mNcol = 6
    Rcol = 2
    Mrow = 2
    
    For Rrow = 2 To 200
    
    If Sheets("HTML_Raw").Cells(Rrow, Rcol).Text = Sheets("Master_Name_List").Cells(Mrow, Mcol).Text Then _
    Sheets("HTML_Raw").Cells(Rrow, Rcol).Text = _
    Sheets("Master_Name_List").Cells(Mrow, mNcol).Text
    Else: If Sheets("HTML_Raw").Cells(row, Rcol).Text <> Sheets("Master_Name_List").Cells(Mrow, Mcol).Text Then _
    Mrow = Mrow + 1
    
    End If
       
    Next Rrow
    End Sub
    Here's my Attempt at a Select Case way of doing this (also doesn't work but looks much cleaner)
    Sub CaseTry1()
    Dim Rrow As Integer
    Dim Rcol As Integer
    Dim Mrow As Integer
    Dim Mcol As Integer
    Dim mNcol As Integer
    Dim Name As String
    Dim CoName As String
    Dim RawName As String
    
    Mcol = 2
    mNcol = 6
    Rcol = 2
    Mrow = 2
    MasterN = Sheets("Master_Name_List").Cells(Mrow, mNcol)
    CoName = Sheets("Master_Name_List").Cells(Mrow, Mcol)
    RawName = Sheets("HTML_Raw").Cells(Rrow, Rcol)
    
    
    Select Case CoName
    Case Is = RawName
    RawName = MasterN And Rrow = Rrow + 1
    Case Else
    Mrow = Mrow + 1
    End Select
    End Sub
    Last edited by MrSir; 07-03-2012 at 02:49 PM. Reason: Additional Info

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1