Solved

Add additional function

Posted on 2011-02-24
4
288 Views
Last Modified: 2012-05-11
Hi Experts,

I would like to request Experts help to add additional function in the attached script. Currently data at Validation2 sheet only able to crosscheck data from column B with data at “Data” sheet and update Yes/No at column C (Validation2). I would like to expend the crosschecking data for all “Type” data at row 1 (Column E,H,K,N,Q,T until BV – Column under “Type” header) and update Yes/No (Column C until BW – column under “Status” header). Hope Experts will help me to create this feature.



Sub Compare()
  
  
Dim oDic As Object, vData As Variant, i As Long, v, vOut(), j As Long

Set oDic = CreateObject("Scripting.Dictionary")
vData = Sheets("Data").Range("A1").CurrentRegion.Value
v = Sheets("Validation2").Range("B2", Sheets("Validation2").Range("B" & Rows.Count).End(xlUp))
ReDim vOut(1 To UBound(v, 1))

With oDic
    For j = LBound(vData, 2) To UBound(vData, 2)
        For i = LBound(vData, 1) To UBound(vData, 1)
            If Not IsEmpty(vData(i, j)) And Not .Exists(vData(i, j)) Then
                .Add vData(i, j), vData(i, j)
            End If
        Next i
    Next j
    For i = LBound(v, 1) To UBound(v, 1)
        If .Exists(v(i, 1)) Then
            vOut(i) = "Yes"
        Else
            vOut(i) = "No"
        End If
    Next i
End With

Sheets("Validation2").Range("C2").Resize(i - 1) = Application.Transpose(vOut)
   
End Sub

Open in new window

Data-Validation.xls
0
Comment
Question by:Cartillo
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 34977012
Please kindly find the attached that may works for you.

Dim oDic As Object, vData As Variant, i As Long, v, vOut(), j As Long, k As Integer

Set oDic = CreateObject("Scripting.Dictionary")
vData = Sheets("Data").Range("A1").CurrentRegion.Value

For k = 2 To 74 Step 3

    If k <= 26 Then
        schar = Chr(64 + k)
    Else
        schar = Chr(Int(k / 26) + 64) & Chr(k Mod 26 + 64)
    End If
    
    If k < 26 Then
        tchar = Chr(65 + k)
    Else
        tchar = Chr(Int(k / 26) + 64) & Chr(k Mod 26 + 65)
    End If
    
v = Sheets("Validation2").Range(schar & "2", Sheets("Validation2").Range(schar & Rows.Count).End(xlUp))
ReDim vOut(1 To UBound(v, 1))

With oDic
    For j = LBound(vData, 2) To UBound(vData, 2)
        For i = LBound(vData, 1) To UBound(vData, 1)
            If Not IsEmpty(vData(i, j)) And Not .Exists(vData(i, j)) Then
                .Add vData(i, j), vData(i, j)
            End If
        Next i
    Next j
    For i = LBound(v, 1) To UBound(v, 1)
        If .Exists(v(i, 1)) Then
            vOut(i) = "Yes"
        Else
            vOut(i) = "No"
        End If
    Next i
End With

Sheets("Validation2").Range(tchar & "2").Resize(i - 1) = Application.Transpose(vOut)

Next k

Open in new window


Data-Validation.xls
0
 

Author Comment

by:Cartillo
ID: 34977379
Hi,

Thanks for the great solution. I need one help. The Status column at Validation sheet is actually  was created manually after the data was exported from the different source. Is that any possible to add “Status” column atomically after “type” column while we run the macro. Hope you will consider this request. I have attached the actual Validation sheet before I add “status” column for your kind perusal. Hope you will consider this request.  

Data-Validation.xls
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 500 total points
ID: 34977597
Here it is:

Sub Compare()
  
Dim oDic As Object, vData As Variant, i As Long, v, vOut(), j As Long, k As Integer

Set oDic = CreateObject("Scripting.Dictionary")
vData = Sheets("Data").Range("A1").CurrentRegion.Value

For k = 2 To 74 Step 3

    If k <= 26 Then
        schar = Chr(64 + k)
    Else
        schar = Chr(Int(k / 26) + 64) & Chr(k Mod 26 + 64)
    End If
    
    If k < 26 Then
        tchar = Chr(65 + k)
    Else
        tchar = Chr(Int(k / 26) + 64) & Chr(k Mod 26 + 65)
    End If
    
v = Sheets("Validation2").Range(schar & "2", Sheets("Validation2").Range(schar & Rows.Count).End(xlUp))

Sheets("Validation2").Range(schar & "1").EntireColumn.Offset(0, 1).Insert
Sheets("Validation2").Range(tchar & "1").Value = "Status"

ReDim vOut(1 To UBound(v, 1))

With oDic
    For j = LBound(vData, 2) To UBound(vData, 2)
        For i = LBound(vData, 1) To UBound(vData, 1)
            If Not IsEmpty(vData(i, j)) And Not .Exists(vData(i, j)) Then
                .Add vData(i, j), vData(i, j)
            End If
        Next i
    Next j
    For i = LBound(v, 1) To UBound(v, 1)
        If .Exists(v(i, 1)) Then
            vOut(i) = "Yes"
        Else
            vOut(i) = "No"
        End If
    Next i
End With

Sheets("Validation2").Range(tchar & "2").Resize(i - 1) = Application.Transpose(vOut)


Next k
   
End Sub

Open in new window


Hope this helps.
0
 

Author Closing Comment

by:Cartillo
ID: 34977672
Hi,

Thanks a lot for the great help
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question