I'm working on a macro that will combine 2 ticket lists together. I have a problem with a loop I am using to find the column number of needed columns. One variable (KJtknrCol) is properly defined while the loop is running (confirmed with message box prompt) but as soon as the script is out of the loop, the value for my variable is missing (also confirmed by message box prompt). Any help would be appreciated.
Here is my code:
Dim KJtknrCol As Long
KJtknrCol = 0
KKtktnrCol = 0
KLstActvCol = 0
KRatngCol = 0
KstatCol = 0
tmpval1 = 1
Do Until Sheets("TW-KPM Export").Cells(1, tmpval1).Value = ""
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "Active User" Then KassigneeCol = tmpval1
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "Jira-Nr." Then
KJtktnrCol = tmpval1
MsgBox "KJtktnrCol has been found in column " & KJtktnrCol & Chr(13) & "tmpval1 = " & tmpval1
End If
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "KPM-Nr." Then KKtktnrCol = tmpval1
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "Last Activity" Then KLstActvCol = tmpval1
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "Rating" Then KRatngCol = tmpval1
If Sheets("TW-KPM Export").Cells(1, tmpval1).Value = "Ticket Status" Then KstatCol = tmpval1
tmpval1 = tmpval1 + 1
Loop
MsgBox "KJtknrCol (After loop) = " & KJtknrCol
During the loop, KJtknrCol is found in column 5 (correct)

But after the loop, it's as if Excel resets the value

All other variables are working OK.