Locate & copy just two cells!

Daghs

New Member
Joined
Apr 17, 2021
Messages
14
Office Version
  1. 2010
Platform
  1. Windows
Hi

I have two files "Data.csv" & "Output.csv".

In data file just in column "B" I'd like to locate the word "JACK" (remember it would be just once in column "B" & I want to find that).
Now where it's located this cell & in the same row cell of column "A" (just these two cells).
I want to copy and paste it to the Output file's "A2" cell, one thing where I want to use this macro they still use excel 2010 so anyone could suggest any macro it'd be a great help.

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
There is no reply about my question on this forum
At least anybody could suggest how do I delete my post from this forum I couldn't find any delete link!
 
Upvote 0
Do you still need help with it ?
If you do can you provide a sample of Data and Output ?
Are they both in the same folder ? Can we hard code the file name and path ?
Are we replacing what is currently in A2 & B2 of Output or inserting a row ?
 
Upvote 0
Thanks atleast you replied and yes I still desperately need the help!

Data.csv & Output.csv are just assumed named to understand what I'm here dealing with anyway that's not the issue.
To make it more easier lets assume Data as .csv & Output as .xlsm file.
And Output.xlsm is the file on which VBA Macro is saved & both files are opened in MS Excel 2010.

you can see In Data.csv file if we look for "JACK01" in column"B"
whatever in column"A" in the same row also be copied & pasted to the Output.xlsm file's cell"A2" just that's it.


Data-csv.jpg

Data.csv image

Output-xlsm.jpg

Output.xlsm image

Output-AfterRuningMacro-xlsm.jpg


Output.xlsm after running the macro.

Again thanks a lot for the response!
 
Upvote 0
I am in Australia and its quite late here. I will have a look tomorrow.
I suspect there is more to it than that but I will start with that. If you have both workbooks open that simplifies things although I will have to use your "assumed" workbook names in the code.
 
Upvote 0
Thanks for reply
You take your time as I mentioned before both workbooks are opened actually this macro is gonna be working in the series of macros so that is why workbooks are already opened! 🙂
 
Upvote 0
Sorry about the delay. See if this works for you.
It assumes both workbooks are open.

VBA Code:
Sub CopyFromCSVtoTHISWB()

    Dim mainWb As Workbook, csvWb As Workbook
    Dim mainSht As Worksheet, csvSht As Worksheet
    Dim findString As String
    Dim csvRow As Long
    
    Set mainWb = ThisWorkbook
    Set csvWb = Workbooks("Data.csv")                   '<--- Change the csv filename (include the extension)
    
    Set mainSht = mainWb.Worksheets("Output")           '<--- Change this to the sheet name you are using
    Set csvSht = csvWb.Worksheets(1)
    
    findString = "JACK01"           ' For a partial match eg "JACK" & "*" - here or findString & "*" inside the Match
    With Application
        csvRow = .IfError(.Match(findString, csvSht.UsedRange.Columns("B"), 0), 0)
    End With
    
    If csvRow = 0 Then
        ' Decide on action required if Not Found
        MsgBox findString & "  Not Found"
        Exit Sub
    End If
    
    mainSht.Range("A2:B2").Value = csvSht.Range("A" & csvRow & ":B" & csvRow).Value
    
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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