So I have a column with data that need to be simplified.
ColumnA ColumnB
Cyan Blue
Navy Blue
Forest Green
I want to write a module that would ask me what to do about cyan when it first encounters it and I have to input blue. But for all the instances that cyan is encountered after this, the corresponding column B needs to be blue.
Sub SIMPLIFY()
RECORD_COUNT = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To RECORD_COUNT
If WorksheetFunction.CountIf(Columns("A"), Range("A" & i)) > 0 Then
RECORD_ROW = WorksheetFunction.Match(Range("A" & i), Columns("A"), 0)
If Cells(RECORD_ROW, 2) <> Empty Then
Cells(i, 2) = Cells(RECORD_ROW, 2)
Else
Cells(i, 2) = InputBox("Input Color for " & Cells(i, 1))
End If
End If
Next i
End Sub
Copy above code to worksheet VBA. The code waits for any changes in column "A" and checks for previous data. It inputs color automatically if it exists, or it asks for color when it's new.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.