I a creating a function in excel using VBA Macro, where it will check if there is a empty cell in a certain column. For example I need to check column A to E and each columns needs to check if there are empty cells, it its empty it will be filled with color red and then add an error comment in column J like " Column A is empty. Please check." (The error is the empty cell) I already have a code for filling the empty cell with color red, what I am having trouble is the error comment because if there are empty cells in different columns but in the same row like column A and column B is empty the Error comment must be "Column A, B is empty. Please check" I just need to insert ", B" in the sentence. And I am having trouble in that condition. please help me
I will attach the code for error comment I just need the condition for inserting ",B" inside the existing comment. Thank you in advance (Note: there are other comments for other functions that I created.)
'Add Error Comment to Column J
cellAddress= "J" & i
tgtValue = "column A is empty. Please check"
If Range(cellAddress).Value = "" Then
Range(celladdress).Value = "->" + tgtValue
Elself Range(cellAddress).Value <> "" And InStr(1,Range(cellAddress).Value, tgtValue, vbTextCompare) = 0 Then
Range(cellAddress).Value = Range(cellAddress).Value + " " + tgtvalue
End If
End If
None at the moment as I wasn't able to figure it out. I got this error comment from other functions that I created
First, your
Elselfstatement has a lowercase l instead of an uppercase I (in uppercase it says ELSELF).You might get a better answer if you share more of your code, but based on what you have, to add ",B", try assigning the new value like this: