Surftahiti9386
New Member
- Joined
- Jul 20, 2023
- Messages
- 3
- Office Version
- 2003 or older
- Platform
- Windows
Hello,
I am stuck on a simple idea but yet the code for it might not be that simple...
I am a beginner at coding in VBA, and I am trying to create a sub that selects and paste the values of all the cells in a column that contains today's date when you close the sheet.
Right now I managed to make it work for only two consecutive cells but nothing more.
I need to use a Loop to select all the cells until there is a blank cell, but I cannot do it on my own.
All the dates are in the B column in the sheet I use for testing.
Here's the code that works but only for the first two cells of the array.
I need to insert a "Do Loop Until" into this code...
Thank you.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim fR As Range
Dim fF As Range
With Worksheets("Feuil1").Range("B1:B10")
Set fR = .Find(what:=Date, after:=.Range("A5"), LookIn:=xlValues, lookat:=xlWhole)
If Not fR Is Nothing Then
Set fF = .FindNext(fR)
Range(fR, fF).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End Sub
I am stuck on a simple idea but yet the code for it might not be that simple...
I am a beginner at coding in VBA, and I am trying to create a sub that selects and paste the values of all the cells in a column that contains today's date when you close the sheet.
Right now I managed to make it work for only two consecutive cells but nothing more.
I need to use a Loop to select all the cells until there is a blank cell, but I cannot do it on my own.
All the dates are in the B column in the sheet I use for testing.
Here's the code that works but only for the first two cells of the array.
I need to insert a "Do Loop Until" into this code...
Thank you.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim fR As Range
Dim fF As Range
With Worksheets("Feuil1").Range("B1:B10")
Set fR = .Find(what:=Date, after:=.Range("A5"), LookIn:=xlValues, lookat:=xlWhole)
If Not fR Is Nothing Then
Set fF = .FindNext(fR)
Range(fR, fF).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End Sub