Forum Discussion
doit_2729
Dec 31, 2021Copper 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
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 Subdoit_2729
Jan 03, 2022Copper Contributor
Awesome.! 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.
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.