VBA to move data to another sheet but on the next available line?

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi All,

i am trying to do a VBA to copy data from one sheet to another but on the next available line. when it pastes it should be as a value. once its done this it goes back to the other tab and delete the data its copied. for example:

i have data in sheet 1 the data range is A:I down to wherever is finishes. this needs to be copied and moved to the next sheet (sheet 2) find the next available line once pasted the VBA goes back to sheet 1 and deletes the data copied.

the macro i have been using is below but i have found i get stuck after the data is copied as it is looking for A41 (Range("A41").Select)

Sub Move_Billed_Cases()
'
' Move_Billed_Cases Macro
'


'
Application.Goto Reference:="R5C1"
Range("A6:I6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveSheet.Next.Select
Application.Goto Reference:="R5C1"
Selection.End(xlDown).Select
Range("A41").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A41").Select
ActiveSheet.Previous.Select
Application.Goto Reference:="R5C1"
Range("A6:H6").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A6").Select
End Sub


thank you!
 
Ok, then try this...

Code:
Sub Move_Billed_Cases()


    Dim ws As Worksheet: Set ws = ActiveSheet
    Dim cArr As Variant
    Dim cRng As Range
    Dim lRow1 As Long, lRow2 As Long
    
    lRow1 = Cells(Rows.Count, 1).End(xlUp).Row
    lRow2 = ActiveSheet.Next.Cells(Rows.Count, 1).End(xlUp).Row + 1
    cArr = Range("A6:I" & lRow1)
    Set cRng = Range("A6:I" & lRow1)
    ws.Next.Range("A" & lRow2).Resize(UBound(cArr, 1), UBound(cArr, 2)) = cArr
    cRng.Delete
    Range("A6").Select
    
End Sub
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Well it took a little back and forth, but I am glad it is working for you. I was happy to help. Thanks for the feedback!
 
Upvote 0

Forum statistics

Threads
1,215,844
Messages
6,127,245
Members
449,372
Latest member
charlottedv

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