userform copy paste

chris2727272727

Board Regular
Joined
Jul 10, 2005
Messages
152
Dim a
Dim activecell

Dim keyboard
Dim tina
Dim bina


On Error Resume Next

i = 1
UserForm2.TextBox1.MultiLine = True
UserForm2.Caption = "First Aid Training Overdue"
lastrow = Range("c65536").End(xlUp).Row
For Each cell In Range("f9:m" & lastrow)
a = cell.Row
Application.ScreenUpdating = False
If cell.Value < DateTime.Date And cell.Value > DateTime.Date - 365 And cell.Font.Strikethrough = False Then
Application.Union(Range("a" & a, "d" & a), cell).Copy

UserForm2.TextBox1.Paste
End If
Next
Application.ScreenUpdating = True
UserForm2.Show
End Sub


I have the above code the trouble is that when it runs it copies all the line to the text box i only want it to copy say for example it picks an overdue date on "a7" i want it to copy a5:d5 inclusive and a8 but instead it copies all of the row to the left of the cell it finds ie a5:a8 inclusive.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello, chris2727272727,

Seems to me like you are messing up some references (a5 ... a7 ?)in your explanation and also you write "left" while I think you mean "right". So perhaps I'm missing something?

this line can be problematic
Application.Union(Range("a" & a, "d" & a), cell).Copy
example: this will produce an error
Union(Range("A1:D1"), Range("D2")).Copy

please tell again what you're trying to do

kind regards,
Erik
 
Upvote 0
Copy Paste

It only copies when the condition is true ie it scolls through the sheet and copies when the condition is true
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top