Chris Davison
MrExcel MVP
- Joined
- Feb 15, 2002
- Messages
- 1,790
Happy New Year all,
I have an already-declared string variable that is turning itself into an integer variable and causing me problems....
I'm not sure why this is happening.
The delete_exit variable has been declared as a string - I was expecting it to be "vbYes" or "vbNo", dependant upon the result of the user's reaction to various message boxes during the macro.
I added a line : msgbox(delete_exit) to show the value of this variable which alerted me to it suddenly becoming an integer, 6 or 7, during the macro.
Here's the code :
any ideas why the variable is changing from a string to an integer ?
cheers
Chris
I have an already-declared string variable that is turning itself into an integer variable and causing me problems....
I'm not sure why this is happening.
The delete_exit variable has been declared as a string - I was expecting it to be "vbYes" or "vbNo", dependant upon the result of the user's reaction to various message boxes during the macro.
I added a line : msgbox(delete_exit) to show the value of this variable which alerted me to it suddenly becoming an integer, 6 or 7, during the macro.
Here's the code :
Code:
Sub delete_specific_contract()
Dim delete_exit As String
Dim cell As Range
'clear old info
Range("delete_number").ClearContents
UF_warning.Show
UF_delete_specific_contract.Show
'exit if "none - exit" was selected
If Range("delete_number").Value = "none" Then
Exit Sub
End If
'check contract end date
If Worksheets("c_" & Range("delete_number")).Range("F5").Value > Date Then
delete_exit = "vbYes"
Worksheets("c_" & Range("delete_number")).Select
Worksheets("c_" & Range("delete_number")).Range("F5").Select
delete_exit = MsgBox("Contract number " & Range("delete_number").Value & "'s finish date is in the future." & Chr(10) & Chr(10) & "Do you want to CANCEL deleting this contract ?", vbYesNo)
If delete_exit = "vbYes" Then
Exit Sub
End If
End If
'check contract's details to see if any plant are not yet returned
With Worksheets("c_" & Range("delete_number"))
For Each cell In Range(.Range("F8"), .Range("F65536").End(xlUp))
If IsEmpty(cell.Offset(0, 1)) = True Then
delete_exit = "vbYes"
Worksheets("c_" & Range("delete_number")).Select
cell.Offset(0, 1).Select
delete_exit = MsgBox("Contract number " & Range("delete_number").Value & " still has plant that looks like it has yet to be returned." & Chr(10) & Chr(10) & "Do you want to CANCEL deleting this contract ?", vbYesNo)
If delete_exit = "vbYes" Then
Exit Sub
End If
End If
Next cell
End With
'last chance confirm message
With Worksheets("c_" & Range("delete_number"))
delete_exit = "vbYes"
Worksheets("c_" & Range("delete_number")).Select
Worksheets("c_" & Range("delete_number")).Range("D5").Select
delete_exit = MsgBox("Contract number " & Range("delete_number").Value & Chr(10) & Chr(10) & "Do you want to CANCEL deleting this contract ?", vbYesNo)
'this is where it's changing
MsgBox (delete_exit)
If delete_exit = "vbYes" Then
Exit Sub
End If
If delete_exit = "vbNo" Then
Application.DisplayAlerts = False
'delete the sheet
.Delete
Application.DisplayAlerts = True
'delete the record from the contract database
For Each cell In Range("contract_number_range")
If cell.Value = Range("delete_number").Value Then
Range(cell, cell.Offset(0, 3)).Delete Shift:=xlUp
End If
Next cell
MsgBox ("Contract number " & Range("delete_number").Value & " deleted")
End If
End With
End Sub
cheers
Chris