| | | |
Uploading ....
The following macro increments the count in Column E, If the value in Range 'A1' is present in Range(D1:D100); Else the value is added in Column D- Public Sub addToTable()
-
- Dim searchItem as String
- searchItem = Range("A1") 'Input Range
-
- Dim searchRegion,count as Range
- Set searchRegion = Range("D1:D100") 'Table Range
-
- Dim nextEmptyRow as Integer
-
- For each cell in searchRegion
- If(ucase(cell.value) = ucase(searchItem)) Then
- 'Increment the count if the value is present and exit
- set count = Cells(cell.row, cell.column+1)
- count.value = count.value + 1
- Exit Sub
- End If
- Next cell
-
- nextEmptyRow = searchRegion.End(xlDown).Row
-
- 'Inserting new value to the table if the value is not present
- cells(nextEmptyRow+1,1).EntireRow.Insert
- cells(nextEmptyRow+1, searchRegion.column).value = searchItem
- cells(nextEmptyRow+1, searchRegion.column+1).value = 1
-
- End Sub
|
|
|
| | | |
|