Help please - Code keeps pasting 34 rows instead of 1

K_Stevs1

New Member
Joined
Jan 27, 2022
Messages
27
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi my I want my code to copy and paste the column of data, to the next empty row in the stated sheet.

It is currently copying the data to the row in the correct sheet, but doing 34 times. Can someone please help advise where I am going wrong?

VBA Code:
Sub CopyData()
   
    Application.ScreenUpdating = False
   
    Dim srcWS As Worksheet, team As Range, lRow As Long, lRow2 As Long
    Set srcWS = Sheets("Form")
    lRow = Range("B" & Rows.Count).End(xlUp).Row
   
        With Sheets(Range("B5").Value)
            lRow2 = .Range("A" & .Rows.Count).End(xlUp).Row + 1
            .Range("A" & lRow2).Resize(lRow).Value = Range("B8")
            .Range("B" & lRow2).Resize(lRow).Value = Range("B9")
            .Range("C" & lRow2).Resize(lRow).Value = Range("B10")
            .Range("D" & lRow2).Resize(lRow).Value = Range("B11")
            .Range("E" & lRow2).Resize(lRow).Value = Range("B12")
            .Range("F" & lRow2).Resize(lRow).Value = Range("B13")
            .Range("G" & lRow2).Resize(lRow).Value = Range("B14")

        End With
     
    Application.ScreenUpdating = True
   
    Range("B5").ClearContents
    Range("E5").ClearContents
    Range("H5").ClearContents
    Range("B8", "B19").ClearContents

 MsgBox ("Submitted Successfully")
End Sub

Picture of the form in image 1
Picture 2 is what is coming out as in the desired tab
 

Attachments

  • Form sample.jpg
    Form sample.jpg
    192.9 KB · Views: 43
  • Outcome.jpg
    Outcome.jpg
    227.3 KB · Views: 26

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It's the part in red that is doing it
Rich (BB code):
.Range("A" & lRow2).Resize(lRow).Value = Range("B8")
you need to remove it from all lines.
 
Upvote 0
You could also slim down the code like
VBA Code:
        With Sheets(Range("B5").Value)
            lRow2 = .Range("A" & .Rows.count).End(xlUp).Row + 1
            .Range("A" & lRow2).Resize(, 7).Value = Application.Transpose(Range("B8:B14").Value)
        End With
 
Upvote 1
Solution
You could also slim down the code like
VBA Code:
        With Sheets(Range("B5").Value)
            lRow2 = .Range("A" & .Rows.count).End(xlUp).Row + 1
            .Range("A" & lRow2).Resize(, 7).Value = Application.Transpose(Range("B8:B14").Value)
        End With
Thank you so much worked perfectly
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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