Copy specific cells

Status
Not open for further replies.

lunatu

Board Regular
Joined
Feb 5, 2021
Messages
77
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Hi! Maybe a silly and simple question but didn't find an answer...
I want to copy from Sheet 1 rows from columns A-B and E-I into Sheet 2 columns C-J. I was using this code to select entire row but like to change now...:

Sub CopyCell()
Dim LR As Long, i As Long
With Sheets("Sheet 1")
LR = .Range("H" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If .Range("H" & i).Value = "Sales Person 1" And .Range("J" & i).Value = "Sold" Then .Rows(i).copy Destination:=Sheets("Sheet 2").Range("A" & Rows.Count).End(xlUp).Offset(1)
Next i
End With
End Sub

Thanks in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How would you copy 7 columns across to where there are 8 target columns?
 
Upvote 0
I see, try this ...

VBA Code:
Sub CopyCell()
    Dim LR As Long, i As Long
    With Sheets("Sheet 1")
        LR = .Range("H" & .Rows.Count).End(xlUp).Row
        For i = 1 To LR
            If .Range("H" & i).Value = "Sales Person 1" And .Range("J" & i).Value = "Sold" Then
                .Range("A" & i).Resize(1, 2).Copy Sheets("Sheet 2").Range("C" & Rows.Count).End(xlUp).Offset(1)
                .Range("E" & i).Resize(1, 5).Copy Sheets("Sheet 2").Range("E" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next i
    End With
End Sub
 
Upvote 0
Solution
You are welcome and thanks for letting me know (y)
 
Upvote 0
Hi,
getting back to this... other columns (not C-I) in sheet2 includes some formulas and data validation but all them are disappeared after running this macro. Any idea how to fix this?
 
Upvote 0
It's very unlikely that my macro is responsible for that since it doesn't copy entire rows but just a few cells as per your request in post #1:
I want to copy from Sheet 1 rows from columns A-B and E-I into Sheet 2 columns C-J. I was using this code to select entire row but like to change now...:

When I ignore both the "Sales Person 1" & "Sold" comparison conditions, the result of the macro is per images below, so there's something else going on:

Before:

ScreenShot280.jpg
ScreenShot281.jpg



After:
ScreenShot280.jpg
ScreenShot282.jpg
 
Upvote 0
Hi, yes you're right - it is not because of that macro...
Based on value changing in sheet1 I have macro running automatically two macros, the one above and removing duplicates with this macro:

Sub RemoveDuplicates()

Dim rng As Range

Set rng = ThisWorkbook.Sheets("Sales Person 1").UsedRange

rng.RemoveDuplicates Columns:=5, Header:=xlYes

End S
ub

This deletes the whole row, inc. data validation and formulas in other cells. Need to figure out how to remove duplicates but not change other cells :unsure:
 
Upvote 0
In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

As you have started a new thread for this question, I'm closing this one.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,902
Messages
6,122,161
Members
449,069
Latest member
msilva74

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