VBA to paste selection above second none blank in range

nadavrock

New Member
Joined
May 15, 2019
Messages
24
i have this code

Sub taskstime2()
'
' taskstime2 Macro
'
' Keyboard Shortcut: Ctrl+t
'
Dim myCells1 As Range
Set myCells1 = Selection
Windows("5. schdule.xlsm").Activate
myCells1.Copy Sheets("1. schdule").Range("hm" & Rows.Count).End(xlUp).Offset(1, 0)


End Sub

it takes selection and paste it after the last nonblank in column hm. i want it to paste above the second noneblank in that column. first cell in column hm is title "tasks" below it are completed tasks. each time i insert row moving them down so the second noneblank changes. the way i work the most recent goes at the top not the bottom while the top row is used for the title of the column.
how do i tweak the above code to provide what im looking for?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
if it helps this gets the second noneblank but i dont know how to use it in vba
=INDEX(GK1:GK13, AGGREGATE(15, 6, ROW(1:13)/SIGN(LEN(GK1:GK13)), 2))
 
Upvote 0
my solution:



' Macron copy to tasks time




Sub taskstime2()
'
' taskstime2 Macro
'
' Keyboard Shortcut: Ctrl+t
'


Dim Rng As Range
Dim WorkRng As Range
Dim WorkRng2 As Range
Dim counter As Integer
Dim counter2 As Integer
Dim rangeletters As String
Dim stringsum As String
Dim topblank As Range
Dim myCells As Range
Set myCells = selection
Set WorkRng = Workbooks("5. schdule").Worksheets("1. schdule").Range("GY1:GY30")



selection.Copy

counter = 0

On Error Resume Next


For Each Rng In WorkRng


If Rng.Value = "" Then
counter = counter + 1
End If
Next

counter2 = counter + 2

stringsum = ("GY" & CStr(counter2))
Set topblank = Range(stringsum)


Set WorkRng2 = Workbooks("5. schdule").Worksheets("1. schdule").Range("topblank")


Windows("5. schdule.xlsm").Activate
WorkRng2.Select
ActiveSheet.Paste













End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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