Filehost.ro - gazduire fisiere
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
ro_xy20 pe Simpatie.ro
Femeie
24 ani
Bucuresti
cauta Barbat
24 - 45 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[EXCEL] Macro to memorize dates in a column [VBA]

Pagini: 1 Moderat de TRaP, TonyTzu
#1
Mrrrr
AdMiN
Postari: 2388
Source:
https://www.computing.net/answers/offic ... 21236.html

I have an excel file in which I want to complete a year's deliveries that are made on a daily basis. I will take a simple example:
- assume column A has 5000 rows completed with formula =TODAY()
- assume column B is blank now, but at the end of today, it will have 50 cells completed

What I wanted was to get a macro to memorize today in column A if the corresponding cell in column B is completed. And DerbyDad03 from computing.net provided.

This code should be inserted in the code of the sheet. In VBA, right click on the sheet you want it to work on, select View Code and paste it there. This code will run automatically each time you make a change to the sheet.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRow As Long
Dim c As Range

On Error GoTo CleanExit

'Determine if change was made to Column B
   If Target.Column = 2 Then
    Application.EnableEvents = False

'Loop through range, changing Column A as appropriate.
       For Each c In Range(Target.Address)
         If c = "" Then
           Range("A" & c.Row).Formula = "=TODAY()"
         Else: Range("A" & c.Row) = Range("A" & c.Row).Value
         End If
       Next
   
CleanExit:
    Application.EnableEvents = True
   
   End If
End Sub


_______________________________________


 
   
#2
Mrrrr
AdMiN
Postari: 2388
Keywords: excel worksheet change

_______________________________________


 
   
Pagini: 1  
Mergi la