If cell is equals value copy another cell

Calinora

New Member
Joined
Oct 9, 2018
Messages
13
I hope you can help me!

I am struggling to get this function to work. I have a spreadsheet with X's on, as if they were ticks. Basically I need to copy cell A if F = x.

Code:
  Dim lRow As Long


    'Determine the last Row.
     lRow = shTarget.Cells.Find("*", LookIn:=xlValues, Searchorder:=xlByRows, Searchdirection:=xlPrevious).Row
     
    For Each Cell In Range("F1:F500")
        If Cell.Value = "X" Then
        Range("A" & Rows.Count).End(xlUp).Copy
        shTarget.Cells(lRow, 11).PasteSpecial xlPasteValuesAndNumberFormats
    
        End If
Next Cell

This is what I have so far. Something is wrong with it, I know as much, I just don't know what. shTarget and shsource is set in my initial code. it is currently inserting all the cells into K15 or 16. (Merged cell)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I would suggest that you unmerge any merged cells because they create havoc for Excel macros. It looks like you want to copy the value in column A for any cell in column F that contains an "X". For example, if F5 contains an "X", you want to copy cell A5. If F10 contains an "X", you want to copy cell A10 and so on. If this is correct, where do you want to paste the copied cells? Also, could you please post your entire code?
 
Upvote 0
The merged cells do not pose a problem. I have fixed the point where it copies the values to, but it copies them into the same cell. I need it to copy cell in A if cell in F is X. The entire code is very long, and this sub in it is the only thing not working.
 
Upvote 0
It needs to go to the next empty line after inserting the first value where f equals x. That’s what’s missing at the moment.

I want it to paste it to my other spreadsheet in column 11 in the last empty row.
 
Last edited:
Upvote 0
I want it to paste it to my other spreadsheet in column 11 in the last empty row.
It looks like you are calculating the last populated row. But you do not want to post it there, but rather the first blank cell AFTER that.
So the row number you would want to paste to should be "lRow + 1", not "lRow".
 
Upvote 0

Forum statistics

Threads
1,224,759
Messages
6,180,813
Members
452,996
Latest member
nelsonsix66

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