Moving row to another sheet, with pasting starting in Column B

cornishpasty55

New Member
Joined
Feb 2, 2021
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I would like to move rows from one sheet to another, depending on the content in Column Z. The value for go-ahead is "0" (as this means there are 0 blank cells in the row).

I have managed to move my completed rows from "Complete" to the next available row in "Archive". This pasting into "Archive" starts in Column A. However, I would like the data to start pasting in Column B of Sheet 2, thus leaving Column A empty. I'm thinking I'll need the use of the Offset function, but I'm not sure how to get this working.

Any help is greatly appreciated!


VBA Code:
Sub Submit_Request()

    Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim J As Long
    Dim K As Long
    I = Worksheets("Complete").UsedRange.Rows.Count
    J = Worksheets("Archive").UsedRange.Rows.Count
    If J = 1 Then
        If Application.WorksheetFunction.CountA(Worksheets("Archive").UsedRange) = 0 Then J = 0
    End If
    Set xRg = Worksheets("Complete").Range("Z3:Z" & I)
    On Error Resume Next
    Application.ScreenUpdating = False
    For K = 1 To xRg.Count
        If CStr(xRg(K).Value) = "0" Then
            xRg(K).EntireRow.Copy Destination:=Worksheets("Archive").Range("A" & J + 1)
            xRg(K).EntireRow.Delete
            If CStr(xRg(K).Value) = "0" Then
                K = K - 1
            End If
            J = J + 1
        End If
    Next
    Application.ScreenUpdating = True
      
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
All you should need to do is change 'A' to 'B' here.
VBA Code:
            xRg(K).EntireRow.Copy Destination:=Worksheets("Archive").Range("A" & J + 1)
[/code[]
 
Upvote 0
Thank you for your suggestion.

Unfortunately, if I replace the 'A' with 'B' nothing appears in my Archive sheet. The row is removed from the Completed sheet, but does not appear at all in my Archive sheet.
 
Upvote 0
Didn't notice you were copying the entire row.

Try this, change the 26 to reflect the no of columns you want to copy.
VBA Code:
Sub Submit_Request()

Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long

    I = Worksheets("Complete").UsedRange.Rows.Count
    J = Worksheets("Archive").UsedRange.Rows.Count
    
    If J = 1 Then
        If Application.WorksheetFunction.CountA(Worksheets("Archive").UsedRange) = 0 Then J = 0
    End If

    Set xRg = Worksheets("Complete").Range("Z3:Z" & I)

    Application.ScreenUpdating = False

    For K = xRg.Count To 1 Step -1
        If CStr(xRg(K).Value) = "0" Then
            xRg(K).EntireRow.Resize(, 26).Copy Destination:=Worksheets("Archive").Range("B" & J + 1)
            xRg(K).EntireRow.Delete
            J = J + 1
        End If
    Next

    Application.ScreenUpdating = True
 
Upvote 0
Solution

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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