I have a macro that searches a certain Range for a code that was entered using a Userform. then determines the value that is the closest to the right from the matching cell in that range (only the QUANTITY columns will be found in order to use them for other calculations). The sheet, however, is made for the 12 months of a year, and after the last month, there is another column with a formula. I want the "TOTAL" ("AP") column and the subsequent ones to remain unaffected by the code.
The code I'm working with is as follows (please note that the code continues, but I don't think the other portions are important):
Private Sub CommandButton1_Click()
Dim cell As Range
'FINDS THE MATCHING CODE FROM THE USERFORM
Set cell = Sheets("TEST").Range("C6:C42").Find(What:=TextBox1, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
'IF SOMETHING IS FOUND THEN...
If Not cell Is Nothing Then
If cell.End(xlToRight).Column = AP Then 'HERE I AM HAVING TROUBLE FIGURING HOW TO DECLARE THE COLUMN
MsgBox "AP" 'DO SOMETHING...
End If
'MORE HERE