+ Reply to Thread
Results 1 to 4 of 4

Dynamic Name range with comparison of variables in column

Hybrid View

  1. #1
    Registered User
    Join Date
    10-06-2011
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    34

    Dynamic Name range with comparison of variables in column

    Please I need help with this:

    I have a defined table name with more that 9 columns (i have 4 columns for an example). I want the last column (column 4) to always compare variables in column 2 and 3 and populate (using VBA because i have about 40 columns in the original data). I used alot of IF Then statement with the Cell (i,j) to write the VBA

    Everything worked but the problem is that when I add an additional column to the table, I have to keep manually changing the cell ranges (Cell (i,j)). Is there a way to make VBA know the column headers so that when I add a new column, I don't have to keep changing the range.

    see attached example

    Thanks!!!!!!
    Attached Files Attached Files
    Last edited by cceze; 04-12-2012 at 04:03 PM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: Dynamic Name range with comparison of variables in column

    One possibility is to create a named range of a cell in the first compare column and use it to calculate the starting column.
    Sub Compare()
        Dim i As Long
        Dim iLastRow As Long
        Dim iName1Col As Long
        
        iLastRow = Range("A65536").End(xlUp).Row
        iName1Col = Range("Name1").Column 'assumes an existing named range
        For i = 1 To iLastRow
            If Cells(i, iName1Col).Value = "we" And _
               Cells(i, iName1Col + 1).Value = "nate" Then
                Cells(i, iName1Col + 2).Value = "good"
            End If
        Next i
    End Sub

  3. #3
    Registered User
    Join Date
    10-06-2011
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    34

    Re: Dynamic Name range with comparison of variables in column

    Thanks! it worked!

  4. #4
    Registered User
    Join Date
    10-06-2011
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    34

    Re: Dynamic Name range with comparison of variables in column

    Thanks it worked!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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