Hello,
First of all I am not quite sure how to use the Input.xlsx workbook and Sheet1 from it without inputting it in the VBA.
I was thinking of ActiveWorkbook and ActiveSheet, I think it might work, though the code is ran from Code.xlsm
The code has multiple functionalities than have to be tweaked
1) It Deletes the Rows where there are duplicates. This is a bit wrong, as I would have wanted to make it delete the rows if it finds duplicates on columns A&C.
Such as scanning columns A&C and
Code:
If (duplicates are found on both columns A&C) Then delete duplicated row, where it has 2 incidences of duplicate values found on columns A&C.
So far, it deletes the entire row if at least 1 duplicate cell is found on columns A:F
2) It is trying to look for a keyword and based on the results it should copy the offsets in the Input.xlsx file on Sheet1, columns G H I J K (the keyword should not be case sensitive).
The problem is that it stops after the first result is encountered and if I expand the range of the Offset.Value result, it keeps pasting the same value everywhere.
3) After 1) and 2) are done it should copy the values from cells E F G in a .txt file with the output similar to the one found in attachments.
Code:
Key:
Code.xlsm is where the code will ran from
Input.xlsx is the input file (input values on A:F), but will also serve as output for 1) and 2) columns G:K on Sheet1
Test.txt is the output file for 3)
Thank you very much in advance, it is appreciated.
Below, I am also attaching the code from the Code.xlsm file
Code:
Public Sub Test()
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("A:D").RemoveDuplicates Columns:=1, Header:=xlNo
Dim SrchRng As Range, cel11 As Range
Set SrchRng = Workbooks("Input.xlsx").Worksheets("Sheet1").Range("F2:F9999")
For Each cel11 In SrchRng
If InStr(cel11.Value, "nice") > 0 Then
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("G2").Value = cel11.Offset(0, -5).Value
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("H2").Value = cel11.Offset(0, -4).Value
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("I2").Value = cel11.Offset(0, -3).Value
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("J2").Value = cel11.Offset(0, -2).Value
Workbooks("Input.xlsx").Worksheets("Sheet1").Range("K2").Value = cel11.Offset(0, -1).Value
End If
Next cel11
Open ThisWorkbook.Path & "/Test.txt" For Output As #1
Print #1, "*Book Name"; Column_G_Value; "*";
Print #1, "*", Column_H_value, column_I_value, column_J_value, column_K_value; "*";
End Sub
Sheet1 is identical with the below 2 pictures but it has the values input from columns A:F. Everything else from G:K is the output that should be generated by the code as for 1) and 2)
Sheets Expected Answer and Another possible answer within Input.xlsx represent the possible outcome when the code is running tasks 1) and2) as above, and they are just for observation and nothing more.
The only difference between those 2 Sheets is that the former one outputs the offsets near the keyword, whereas the latter outputs the results from Row2 onwards )
I made 2 possible outcome Sheets as I'm not sure which one would be easier to use as an example while creating the code.
Capture.JPG
Capture2.JPG
Finally, I am also attaching the output .txt file that could be generated by the code for 3)
Best wishes
Gordon