cut and paste to the first blank row in another sheet

rickyyy2006

New Member
Joined
Nov 21, 2016
Messages
8
would like to write a program with the below function
If Cell ("J" i) or Cell("L" i) or Cell("N" i) in Sheet1 is not empty where i equals to any integer
Then cut Cell("B" i) to Cell("O" i) in Sheet 1 to the first blank and rows after that in Sheet2
However,I don't know what should variable UUUUU in the below code be.
I stuck in this parts for so long. Can one helps me?
Many thanks


<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;"> Sub CutandPaste()
With ActiveSheet
Dim i As Long
Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet

Set mainsheet = ActiveWorkbook.Sheets("Sheet1")
Set subsheet = ActiveWorkbook.Sheets("Sheet2")

endrow
= mainsheet.Range("A" & mainsheet.Rows.Count).End(xlUp).Row
firsblankrow = subsheet.Range(UUUUU).UUUUU.Row

For i = endrow To 25 Step -1

If mainsheet.Cells(i, "J") <> "" Or mainsheet.Cells(i, "L") <> "" Or mainsheet.Cells(i, "N") <> "" Then
mainsheet
.Range(mainsheet.Cells(i, "B"), mainsheet.Cells(i, "O")).Cut Destination:=subsheet.Range(subsheet.Cells(firsblankrow , "B"), subsheet.Cells(firsblankrow , "O")).Paste
mainsheet.Range(mainsheet.Cells(i, "B"), mainsheet.Cells(i, "O")).Delete '~~> if you want to delete

End If
Next
End With
End Sub</code>
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I suspect you did not write this code. You found it some place and are now trying to make it work for you.

To start with there is no cell ("J",i)

You may have a cell (i,"J")

"J" is a column not a row.

Why not tell us what your wanting to do and give specifics and see if we can help you.

When you use Cells(?,?)

The first ? is the row number and the second ? is the column letter.
 
Last edited:
Upvote 0
I suspect you did not write this code. You found it some place and are now trying to make it work for you.

To start with there is no cell ("J",i)

You may have a cell (i,"J")

"J" is a column not a row.

Why not tell us what your wanting to do and give specifics and see if we can help you.

When you use Cells(?,?)

The first ? is the row number and the second ? is the column letter.

Sorry for the typo.It should be cell(i,"J") etc. The first version of the above code is:

==========================
Sub CutandPaste()
With ActiveSheet
Dim i As Long
Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet

Set mainsheet = ActiveWorkbook.Sheets("Sheet1")
Set subsheet = ActiveWorkbook.Sheets("Sheet2")

endrow = mainsheet.Range("A" & mainsheet.Rows.Count).End(xlUp).Row

For i = endrow To 25 Step -1

If mainsheet.Cells(i, "J") <> "" Or mainsheet.Cells(i, "L") <> "" Or mainsheet.Cells(i, "N") <> "" Then
mainsheet.Range(mainsheet.Cells(i, "B"), mainsheet.Cells(i, "O")).Cut Destination:=subsheet.Range(subsheet.Cells(i + 56, "B"), subsheet.Cells(i + 56, "O")).Paste
mainsheet.Range(mainsheet.Cells(i, "B"), mainsheet.Cells(i, "O")).Delete '~~> if you want to delete

End If
Next
End With
End Sub
=================

Yet, i found it is not a good idea. Cause if cell(i+56,"B") in Subsheetis occupied, my odd data is going to be replaced by new data. Thus, i would like to change "i+56" to another variable which is able to detect the first blank row in Subsheet.

Kindly look for the attached link for my excel data
Mainsheet data: https://i.stack.imgur.com/XlCKg.jpg
Subsheet Data: https://i.stack.imgur.com/yn5b9.jpg

Like i want to move Column B(First AAA) to Column L(Last AAA) of row 25 in Mainsheet to Column B to Column L of row 81 in Subsheet. If now row 81 in Subsheet is not blank, then paste to row 82 in Subsheet.
 
Upvote 0
Try this:

I copied the ranges over. Was not sure if you wanted the original row or selection deleted cut or what.

In one place you say cut but then it appears as if you want the row deleted. No reason to cut if your going to delete.

Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow1 As Long
Dim Lastrowa2 As Long
Lastrow1 = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Lastrow2 = Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Row
    
    For i = 25 To Lastrow1
        If Sheets("Sheet1").Cells(i, "J").Value <> "" Or _
        Sheets("Sheet1").Cells(i, "L").Value <> "" Or _
        Sheets("Sheet1").Cells(i, "N").Value <> "" Then
            Sheets("Sheet1").Range(Cells(i, "B"), Cells(i, "O")).Copy Destination:=Sheets("Sheet2").Range("B" & Lastrow2)
            Lastrow2 = Lastrow2 + 1
    
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,044
Members
452,542
Latest member
Bricklin

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