Excel Sheet
I need to find any colored cell and copy its value (Column A) and the value of the quantity (Column B)
I’m using this snippet of code to iterate any cells of the active sheet:
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Interior.Color = thecolorImlookinfor Then
someVariable = cell.Value
otherVariable = **HERE I NEED THE VALUE OF THE CELL IN THE SAME ROW BUT IN THE NEXT COLUMN**
End If
Next cell
I would like to find a way to obtain the value of the cell immediately on the right (the next column of course)
and I don’t know how can I do.
Obviously, in the image there are column A and Column B but I don’t know which column I get from the search.
Any idea?
Sorry for my English and don’t be afraid to ask if I hadn’t explained myself correctly
The first column of your table is referenced by ActiveSheet.UsedRange.Columns(1).
Offset
is used to get the next cell in the same row.
Microsoft documentation:
Range.Offset property (Excel)
Dim cell As Range
For Each cell In ActiveSheet.UsedRange.Columns(1)
If cell.Interior.Color = thecolorImlookinfor Then
someVariable = cell.Value
otherVariable = cell.Offset(, 1).Value
End If
Next cell
0