VBA Copy and Paste Offset, how to shift pasted values a few cells horizontally

Excel Jason

New Member
Joined
Oct 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I have a VBA script that copies values from one tab and pastes them in the next available row on another tab; However, it pastes the values next to each other. Two of the four values I need pasted a few cells down. Example:

1668181000217.png


Current Script

VBA Code:
Sub Button2()
Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            Worksheets("Dashboard").Range("F7:G7,Q7,S7").Copy
            Worksheets("SKU Tracker").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End If

    Application.ScreenUpdating = True

End Sub

I suspect a quick edit to my code but I'm having a hard time. Thanks!
 

Attachments

  • 1668180882466.png
    1668180882466.png
    9.9 KB · Views: 4

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
@Excel Jason Does this help?

VBA Code:
Sub Button2()
'Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Dim NxtRw As Long
    
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            Rng1 = Worksheets("Dashboard").Range("F7:G7")
            Rng2 = Worksheets("Dashboard").Range("Q7,S7")
            
            With Worksheets("SKU Tracker")
                NxtRw = .Range("C" & Rows.Count).End(xlUp) + 1
                .Range("C" & NxtRw & ":D" & NxtRw) = Worksheets("Dashboard").Range("F7:G7")
                .Range("M" & NxtRw & ":N" & NxtRw) = Worksheets("Dashboard").Range("Q7,S7")
            End With
        
        End If
    
    'Application.ScreenUpdating = True

End Sub
 
Upvote 0
VBA Code:
Sub Button2()
'Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Dim NxtRw As Long
    
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            Rng1 = Worksheets("Dashboard").Range("F7:G7")
            Rng2 = Worksheets("Dashboard").Range("Q7,S7")
            
            With Worksheets("SKU Tracker")
                NxtRw = .Range("C" & Rows.Count).End(xlUp).Row + 1
               
                .Range("C" & NxtRw & ":D" & NxtRw).Value = Worksheets("Dashboard").Range("F7:G7").Value
                .Range("M" & NxtRw & ":N" & NxtRw).Value = Worksheets("Dashboard").Range("Q7,S7").Value
            End With
        
        End If
    
    'Application.ScreenUpdating = True

End Sub
 
Upvote 0
Hey Snake,

It places data in the correct cells but it's grabbing the wrong data: I highlighted the cells it's pulling. It copies the SKU and date correctly but grabs 14,010 from the wrong row (One row below the correct row) and it's also grabbing the wrong volume figures.

1668522136604.png


Result on next Tab:
1668522233456.png
 
Upvote 0
Jason, I fail to see how it is not grabbing F7:G7 and Q7:S7 from dashboard as per your original code?
 
Upvote 0
Agreed,

The values seem to be correct. Here is the VBA just for clarity

VBA Code:
Sub Button2()
'Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Dim NxtRw As Long
    
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            Rng1 = Worksheets("Dashboard").Range("F7:G7")
            Rng2 = Worksheets("Dashboard").Range("Q7,S7")
            
            With Worksheets("SKU Tracker")
                NxtRw = .Range("C" & Rows.Count).End(xlUp).Row + 1
               
                .Range("C" & NxtRw & ":D" & NxtRw).Value = Worksheets("Dashboard").Range("F7:G7").Value
                .Range("M" & NxtRw & ":N" & NxtRw).Value = Worksheets("Dashboard").Range("Q7,S7").Value
            End With
        
        End If
    
    'Application.ScreenUpdating = True

End Sub
 
Upvote 0
So are you now saying that placement and values are correct, so all is good?
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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