Hi All,
I am struggling with a code line for a simple macro.
Thank you in advance for taking some of your time and to anyone who will help me
I have 2 sheets ("data" and "macro").
Sheet "data" contains details of users (column A contains data of user 1, column B of user 2 etc) these data have different colours (yellow, green, etc corresponding to different prices).
I am asking the user of the macro to write down in cell "B5" of sheet "macro" the user that he is looking for.
The macro copies the data of that user and (copy from "data" into "macro sheet") - this part works.
Then the code should calculate the due amount applying two "if" conditions.
If the data in column "D" has colour "green" and "has text/value", then copy the value from a fixed cell (D27) into the corresponding G cell.
In the below code I was able to build the macro working based on the colour.
But I am not able to add the condition "only if D cell contains text or value".
The idea is that the value of D27 should be added only if both conditions are met
Thank you very much for any support or suggestion!
I am struggling with a code line for a simple macro.
Thank you in advance for taking some of your time and to anyone who will help me
I have 2 sheets ("data" and "macro").
Sheet "data" contains details of users (column A contains data of user 1, column B of user 2 etc) these data have different colours (yellow, green, etc corresponding to different prices).
I am asking the user of the macro to write down in cell "B5" of sheet "macro" the user that he is looking for.
The macro copies the data of that user and (copy from "data" into "macro sheet") - this part works.
Then the code should calculate the due amount applying two "if" conditions.
If the data in column "D" has colour "green" and "has text/value", then copy the value from a fixed cell (D27) into the corresponding G cell.
In the below code I was able to build the macro working based on the colour.
But I am not able to add the condition "only if D cell contains text or value".
The idea is that the value of D27 should be added only if both conditions are met
Thank you very much for any support or suggestion!
VBA Code:
Sheets("data").Activate
If Sheets("macro").Range("B5").Value = "Imrich" Then
Sheets("macro").Range("F3:F20").Value = Sheets("data").Range("D3:D20").Value
Sheets("macro").Activate
End If
Dim LR As Long, I As Long
Sheets("data").Activate
LR = Range("D" & Rows.Count).End(xlUp).Row
For I = 1 To LR
If Sheets("data").Range("D" & I).Interior.Color = RGB(255, 255, 0) Then
Sheets("macro").Range("G" & I).Value = Sheets("data").Range("$D$27").Value
ElseIf Sheets("data").Range("D" & I).Interior.Color = RGB(255, 255, 0) Then
Sheets("macro").Range("G" & I).Value = Sheets("data").Range("$D$26").Value
Sheets("macro").Activate
End If
Next I
Sheets("macro").Activate