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>
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>