copying and paste macro

Mr Marvin

New Member
Joined
Sep 8, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
i am using this macro to copy cells which have been selected via checkboxes. The cells start in A1 but when they are pasted into output they are found in cell A10000 odd where i need them to be in A1. Is there something i am missing here.

Also when it is copying the cells over i am copying the entire row where i just need the info in the A column when selected. can anyone assist please

thanks

Sub MoveRowBasedOnCellValue()
'Updated by Extendoffice 2017/11/10
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Email Template").UsedRange.Rows.Count
J = Worksheets("Output").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Output").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Email Template").Range("C1:C" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "True" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Output").Range("A" & J + 1)
J = J + 1
End If
Next
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Most probably its bcos at row 10000 there's some value in present making the whole range Used Range

try clearing everything in "Output Sheet" or just delete it and create a new sheet of the same name.
 
Upvote 0
@SidharthS thank you.

do you know how the code can be adjusted so that it just copies the text in column A and not the entire row. TIA
 
Upvote 0
do you know how the code can be adjusted so that it just copies the text in column A and not the entire row. TIA
Try changing
VBA Code:
xRg(K).EntireRow.Copy Destination:=Worksheets("Output").Range("A" & J + 1)
to
Rich (BB code):
xRg(K).Offset(, -2).Copy Destination:=Worksheets("Output").Range("A" & J + 1)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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