as part of reviewing data, I typically need to manually highlight instances where two columns occur only once in two columns in the same row of data. For example, in a table containing 20 columns and 20K rows there are instances where one column, column user_ID has a unique number which only occurs only once in 20K rows and in a second column called User_ID_second a similar occurrence happens. If a specific row e.g., row 1,287 contains unique values on in both columns (user_ID and User_ID_second) I typically classify them as "isolated" and all other situations as "more than one" in a separate column. In an effort to help myself I recorded the following macro which uses a simple logical statement along with countif and sum.
Columns("J:J").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Table1[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "Calculations"
Range("J2").Select
ActiveCell.FormulaR1C1 = _
"=IF(SUM(COUNTIF([UserID_Number],[@UserID_Number]),COUNTIF([UserID_Number_Second_Column],[@[UserID_Number_Second_Column]]))=2, ""Isolated"",""more than one"")"
Range("J3").Select
Range("Table1[Calculations]").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
This recorded macro gets the job done for smaller datasets, however, my datasets keep on growing and presently my computer freezes and crashes with the present ones which can be over 200K rows long. Is there an easier way of running this simple logical test via VBA?
Aucun commentaire:
Enregistrer un commentaire