ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Clear Cell Content Query (https://www.excelbanter.com/excel-discussion-misc-queries/256981-clear-cell-content-query.html)

captedgar

Clear Cell Content Query
 

Hi there

My Excel Vba shown below inserts time() into a particular cell on my
sheet.
Once inserted, is it possible to clear this cell before my vba code is
re-run?.
My VBA is only entering the time() once and not re-insering the time()
if i change the same cell values after some time i.e.

please advice

Below is my code which inserts time() into a cell.

Private Sub DateModifier(ByVal strTarget As String, ByVal strDestination
As String)
' Checks for a Yes or NA or RB(Rollback) value in strTarget and if
found, modifies the cell in strDestination
If (Range(strTarget + strCurrentRow).Value2 = "Yes") Then
If (Range(strDestination + strCurrentRow).Value2 = "") Then
Range(strDestination + strCurrentRow).Value2 = StaticTime
End If

' Check to see if Log has been rolled back
If (Range(strDestination + strCurrentRow).Value2 Like ("Rolled
Back*")) Then
Range(strDestination + strCurrentRow).Value2 = StaticTime
End If
End If

' Check for an NA status
If (Range(strTarget + strCurrentRow).Value2 = "NA") Then
If (Range(strDestination + strCurrentRow).Value2 = "") Then
Range(strDestination + strCurrentRow).Value2 = "NA"
End If
End If

' Check to see if strTarget changes to "No" but originally was yes
' (if a value is in strDestination we assume a log has happened)
' and append the log with Rolled Back and the date
If (Range(strTarget + strCurrentRow).Value2 = "RB") Then
If Not (Range(strDestination + strCurrentRow).Value2 = "") Then
If Not (Range(strDestination + strCurrentRow).Value2 Like
"*RB*") Then
Range(strDestination + strCurrentRow).Value2 = "RB" +
StaticTime
End If
End If
End If
End Sub




--
captedgar

Daryl S

Clear Cell Content Query
 
Captedgar -

Of course you can clear it manually before you run the code. Better, clear
it at the top of the code you are running. Like this:

Private Sub DateModifier(ByVal strTarget As String, ByVal strDestination
As String)
Range(strDestination + strCurrentRow).Value2 = "" 'Empty out this field to
start with.
' Checks for a Yes or NA or RB(Rollback) value in strTarget and if
found, modifies the cell in strDestination
If (Range(strTarget + strCurrentRow).Value2 = "Yes") Then
If (Range(strDestination + strCurrentRow).Value2 = "") Then
Range(strDestination + strCurrentRow).Value2 = StaticTime
End If

--
Daryl S


"captedgar" wrote:


Hi there

My Excel Vba shown below inserts time() into a particular cell on my
sheet.
Once inserted, is it possible to clear this cell before my vba code is
re-run?.
My VBA is only entering the time() once and not re-insering the time()
if i change the same cell values after some time i.e.

please advice

Below is my code which inserts time() into a cell.

Private Sub DateModifier(ByVal strTarget As String, ByVal strDestination
As String)
' Checks for a Yes or NA or RB(Rollback) value in strTarget and if
found, modifies the cell in strDestination
If (Range(strTarget + strCurrentRow).Value2 = "Yes") Then
If (Range(strDestination + strCurrentRow).Value2 = "") Then
Range(strDestination + strCurrentRow).Value2 = StaticTime
End If

' Check to see if Log has been rolled back
If (Range(strDestination + strCurrentRow).Value2 Like ("Rolled
Back*")) Then
Range(strDestination + strCurrentRow).Value2 = StaticTime
End If
End If

' Check for an NA status
If (Range(strTarget + strCurrentRow).Value2 = "NA") Then
If (Range(strDestination + strCurrentRow).Value2 = "") Then
Range(strDestination + strCurrentRow).Value2 = "NA"
End If
End If

' Check to see if strTarget changes to "No" but originally was yes
' (if a value is in strDestination we assume a log has happened)
' and append the log with Rolled Back and the date
If (Range(strTarget + strCurrentRow).Value2 = "RB") Then
If Not (Range(strDestination + strCurrentRow).Value2 = "") Then
If Not (Range(strDestination + strCurrentRow).Value2 Like
"*RB*") Then
Range(strDestination + strCurrentRow).Value2 = "RB" +
StaticTime
End If
End If
End If
End Sub




--
captedgar
.



All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com