Forum Discussion
doit_2729
Jan 01, 2022Copper Contributor
VBA code to copy & paste data as per Date Criteria
Good day Team, I have already posted same question of some other form but it been long time and did not get any response so, I have hope that I will get some result here. I am new to VBA, so trying...
- Jan 03, 2022
Thanks, I see what is happening. Merged cells don't play nice with VBA. Try this version:
Private Sub CommandButton1_Click() Dim Rg As Range Set Rg = Me.UsedRange.Columns(1).Find(What:=Application.Text(Date, [A16].NumberFormat), LookIn:=xlValues) If Rg Is Nothing Then MsgBox "Today's Date Not Found. Please check the 'Date Received'" ElseIf Rg.Offset(0, 1).Value = "" Then Rg.Offset(0, 1).Resize(, 22).Value2 = [B16:W16].Value2 ElseIf Rg.Offset(0, 1).Offset(1).Value = "" Then Rg.Offset(0, 1).Offset(1).Resize(, 22).Value2 = [B16:W16].Value2 ElseIf Rg.Offset(0, 1).Offset(2).Value = "" Then Rg.Offset(0, 1).Offset(2).Resize(, 22).Value2 = [B16:W16].Value2 Else MsgBox "All three times have been filled!" End If Application.CutCopyMode = False End Sub
doit_2729
Jan 03, 2022Copper Contributor
Thank You again.
Much appreciated.
Yes, this what i was looking for but some reason data is copying in to line not in order when you click 2nd time and 3rd time. See the attached below. ( i have also attached my file here as well)
I don't have words to express my gratutide, this is great help to me.
Thank you again for all your help.
HansVogelaar
Jan 03, 2022MVP
Thanks, I see what is happening. Merged cells don't play nice with VBA. Try this version:
Private Sub CommandButton1_Click()
Dim Rg As Range
Set Rg = Me.UsedRange.Columns(1).Find(What:=Application.Text(Date, [A16].NumberFormat), LookIn:=xlValues)
If Rg Is Nothing Then
MsgBox "Today's Date Not Found. Please check the 'Date Received'"
ElseIf Rg.Offset(0, 1).Value = "" Then
Rg.Offset(0, 1).Resize(, 22).Value2 = [B16:W16].Value2
ElseIf Rg.Offset(0, 1).Offset(1).Value = "" Then
Rg.Offset(0, 1).Offset(1).Resize(, 22).Value2 = [B16:W16].Value2
ElseIf Rg.Offset(0, 1).Offset(2).Value = "" Then
Rg.Offset(0, 1).Offset(2).Resize(, 22).Value2 = [B16:W16].Value2
Else
MsgBox "All three times have been filled!"
End If
Application.CutCopyMode = False
End Sub- doit_2729Jan 03, 2022Copper ContributorAwesome.! It's working the way i need.
You are great Sir.
I cannot thank you enough for helping me out.
āThanks a bunch! Highly appreciated for your time to look in to my request.