Disabling a macro from automatically clearing a cell

davidhall

Board Regular
Joined
Mar 6, 2011
Messages
174
This the beginning part of my code. In cell E4, I have a time stamp generated by another form control button.

The code below references cell E4 but always clears out the cell and I cant figure out why.





Dim Entered_User_Password As String
Dim Current_User_Password As String
Dim Current_Password_Date As Object
Dim Administrator_Password As String
Dim Date_Difference As Long
Dim New_User_Password As String
Range("E4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Set Current_Password_Date = ThisWorkbook.Sheets("Sheet2").Range("E4")
Current_Password_Date.NumberFormat = "mm/dd/yy hh:mm"

Current_User_Password = ThisWorkbook.Sheets("PasswordSheet").Range("A65536").End(xlUp)
Current_Password_Date = ThisWorkbook.Sheets("PasswordSheet").Range("A65536").End(xlUp).Offset(0, 1)
Administrator_Password = "pswd"
Date_Difference = DateDiff("h", Now(), Current_Password_Date)
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try stepping through it using F8 to see where it clears the cell.

By the way, you could reduce the following lines of code:
Range("E4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

to:
With Range("E4")
.Formula = .Value
End With
 
Upvote 0
Do you have any events in the same workbook? Try setting EnableEvents to False at the start of your code, then back to true at the end.
 
Upvote 0
Code:
Range("E4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Uhhh, doesn't this select cell E4, copy it and then paste on to itself ?
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top