Look for value in one column & copy value from another

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,720
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Looking for some advice please to extract some info from my worksheet like below.
The 2 columns in mind are search column D & datate stored in column B

So the code will look in column D for GOLD WING USA & also GOLD WING UK
Once either of the above is found copy the value from column B to column M or O

See screenshot.
Working down my worksheet starting at Row 8
GOLD WING USA will copy the value in the cell that is filled Blue to column M

GOLD WING UK will copy the value in the cell that is filled Red to column O

GOLD WING UK will copy the value in the cell that is filled Green to the next empty cell in column O

GOLD WING UK will copy the value in the cell that is filled White to the next empty cell in column O
 

Attachments

  • EaseUS_2023_10_ 9_16_41_46.jpg
    EaseUS_2023_10_ 9_16_41_46.jpg
    40.4 KB · Views: 30

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If one can look for LIKE ("Gold Wing *) it would be slightly easier I think. However, if you want people to work with data like that you might get help faster if you posted data - at least a copy/paste from your sheet would be better than nothing. Today's our Thanksgiving and I have company for dinner so don't have time to start from scratch.
 
Upvote 0
Hello,
Basically I’m looking to only copy values of GOLD WING of which there are two possibilities,
UK & USA that’s it.

My goal is a list of UK & USA values.
Whether it be in another column or anything really.
 
Upvote 0
Morning,
Im playing with the following just to see how it will work but when i run the command button nothing happens at all.
I dont even get an error.

Below im just trying to get the search / find - copy / paste side working then look into just copying the value from the cell in column D as opposed the whole row

Rich (BB code):
Private Sub GoldWingCountry_Click()
Dim Cell As Range
Dim ws As Worksheet
Set ws = Sheets("MCLIST")

With Sheets("MCLIST")
      For Each Cell In .Range("D8:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
        If Cell.Value = "UK" Then
            .Rows(Cell.Row).Copy Destination:=Sheets("COUNTRYLIST").Rows(Cell.Row)
        End If
    Next Cell
End With
End Sub

Nothing fancy but trying to get it like so,see screenshot
 

Attachments

  • EaseUS_2023_10_10_11_24_36.jpg
    EaseUS_2023_10_10_11_24_36.jpg
    112.5 KB · Views: 12
Upvote 0
Maybe this:
VBA Code:
Private Sub GoldWingCountry_Click()
    Dim Cell As Range
    Dim wsMC As Worksheet
    Dim wsCountry As Worksheet
    
    Set wsMC = Sheets("MCLIST")
    Set wsCountry = Sheets("COUNTRYLIST")
    
    wsCountry.Range("A1") = "GOLD WING UK"
    wsCountry.Range("B1") = "GOLD WING USA"
    
    With wsMC
        For Each Cell In .Range("D8:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
            If Cell.Value = "GOLD WING UK" Then
                Cell.Offset(, -2).Copy wsCountry.Range("A" & Rows.Count).End(xlUp).Offset(1)
            ElseIf Cell.Value = "GOLD WING USA" Then
                Cell.Offset(, -2).Copy wsCountry.Range("B" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next Cell
        Application.CutCopyMode = False
    End With
End Sub

Or without copy/ paste
VBA Code:
Private Sub GoldWingCountry_Click()
    Dim Cell As Range
    Dim wsMC As Worksheet
    Dim wsCountry As Worksheet
    
    Set wsMC = Sheets("MCLIST")
    Set wsCountry = Sheets("COUNTRYLIST")
    
    wsCountry.Range("A1") = "GOLD WING UK"
    wsCountry.Range("B1") = "GOLD WING USA"
    
    With wsMC
        For Each Cell In .Range("D8:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
            If Cell.Value = "GOLD WING UK" Then
                wsCountry.Range("A" & Rows.Count).End(xlUp).Offset(1) = Cell.Offset(, -2)
            ElseIf Cell.Value = "GOLD WING USA" Then
                wsCountry.Range("B" & Rows.Count).End(xlUp).Offset(1) = Cell.Offset(, -2)
            End If
        Next Cell
    End With
End Sub
 
Upvote 0
Many Thanks,
I have used the following from which you kindly advised.

You will see in Red that i added to clear contents from the sheet where values are pasted.
I see when the copy takes place it also takes the background color & also the border lines so on the sheet COUNTYRYLIST not only does the values get pasted but also the background cell color & border lines.

Can you edit the code & show me the added code that i hope you can help with.

Either ONLY copy values & NOT background color / border lines OR when the Range A2;B500 has the contents cleared then also remove background color & border lines.



Rich (BB code):
Private Sub GoldWingCountry_Click()
    Dim Cell As Range
    Dim wsMC As Worksheet
    Dim wsCountry As Worksheet
       
    Set wsMC = Sheets("MCLIST")
    Set wsCountry = Sheets("COUNTRYLIST")
     
    With Sheets("COUNTRYLIST")
        .Range("A2:B500").ClearContents
    End With
        
    wsCountry.Range("A1") = "GOLD WING UK"
    wsCountry.Range("B1") = "GOLD WING USA"
    
    With wsMC
        For Each Cell In .Range("D8:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
            If Cell.Value = "GOLD WING UK" Then
                Cell.Offset(, -2).Copy wsCountry.Range("A" & Rows.Count).End(xlUp).Offset(1)
            ElseIf Cell.Value = "GOLD WING USA" Then
                Cell.Offset(, -2).Copy wsCountry.Range("B" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next Cell
        Application.CutCopyMode = False
    End With
   Sheets("COUNTRYLIST").Select
End Sub
 
Upvote 0
Did you try the second piece of code from post 5?

That is values only.
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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