copy an entire excel case if contains a specific word.

rhaedan77

New Member
Joined
Apr 7, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. MacOS
Hello !

I'm a French teacher, and I need your help to manage an excel document.

I have downloaded thousands of sentences in French with their english translations that I stored in an excel sheet. In another sheet, when I write a word in French in A1, I would like the case B1 to show automatically the French sentences with the matching word, and the case C1 to show the english translation.

For exemple :

Here is my first sheet with the sentences.
Je serai bientôt de retour.I will be back soon.
C’était un méchant lapin.That was an evil bunny.

In the second sheet, I will just write the word :
bientôt
lapin

And I would like the french exemple + the translation to pop up automatically.
bientôtJe serai bientôt de retour.I will be back soon.
lapinC’était un méchant lapin.That was an evil bunny.

Is there any a way to do that ?

Sorry for my crappy english and my poor excel skills :)
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello Please Try this Once and Provide your feedback.
also change the sheet name accrding to your sheet name

VBA Code:
Sub mycode()

Dim i As Integer
Dim j As Integer

Dim lastrow1 As Integer
Dim lastrow2 As Integer

lastrow1 = Worksheets("Sheet1").Range("a1").CurrentRegion.Rows.Count
lastrow2 = Worksheets("Sheet2").Range("a1").CurrentRegion.Rows.Count

For i = 1 To lastrow2
    For j = 1 To lastrow1
        If IsNumeric(VBA.InStr(1, Worksheets("sheet2").Range("a" & i).Value, _
                        Worksheets("sheet1").Range("a" & j).Value, vbTextCompare)) Then
            Worksheets("sheet2").Range("b" & i).Value = Worksheets("sheet1").Range("b" & j).Value
            Exit For
        End If
    Next j
Next i
End Sub
 
Upvote 0
Sub mycode() Dim i As Integer Dim j As Integer Dim lastrow1 As Integer Dim lastrow2 As Integer lastrow1 = Worksheets("Sheet1").Range("a1").CurrentRegion.Rows.Count lastrow2 = Worksheets("Sheet2").Range("a1").CurrentRegion.Rows.Count For i = 1 To lastrow2 For j = 1 To lastrow1 If IsNumeric(VBA.InStr(1, Worksheets("sheet2").Range("a" & i).Value, _ Worksheets("sheet1").Range("a" & j).Value, vbTextCompare)) Then Worksheets("sheet2").Range("b" & i).Value = Worksheets("sheet1").Range("b" & j).Value Exit For End If Next j Next i End Sub
Thanks a lot for your help.

After having past the code, it is said that the "capacity is overflowed".
 

Attachments

  • Capture d’écran 2021-04-07 à 22.56.45.png
    Capture d’écran 2021-04-07 à 22.56.45.png
    138.8 KB · Views: 5
  • Capture d’écran 2021-04-07 à 22.57.36.png
    Capture d’écran 2021-04-07 à 22.57.36.png
    136.7 KB · Views: 5
Upvote 0
Try this once
VBA Code:
Sub mycode()

Dim i As Integer
Dim j As Integer

Dim lastrow1 As Byte
Dim lastrow2 As Byte

lastrow1 = Worksheets("Sheet1").Range("a1").CurrentRegion.Rows.Count
lastrow2 = Worksheets("Sheet2").Range("a1").CurrentRegion.Rows.Count

For i = 1 To lastrow2
    For j = 1 To lastrow1
        If IsNumeric(VBA.InStr(1, Worksheets("sheet2").Range("a" & i).Value, _
                        Worksheets("sheet1").Range("a" & j).Value, vbTextCompare)) Then
            Worksheets("sheet2").Range("b" & i).Value = Worksheets("sheet1").Range("b" & j).Value
            Exit For
        End If
    Next j
Next i
End Sub
 
Upvote 0
Sub mycode() Dim i As Integer Dim j As Integer Dim lastrow1 As Byte Dim lastrow2 As Byte lastrow1 = Worksheets("Sheet1").Range("a1").CurrentRegion.Rows.Count lastrow2 = Worksheets("Sheet2").Range("a1").CurrentRegion.Rows.Count For i = 1 To lastrow2 For j = 1 To lastrow1 If IsNumeric(VBA.InStr(1, Worksheets("sheet2").Range("a" & i).Value, _ Worksheets("sheet1").Range("a" & j).Value, vbTextCompare)) Then Worksheets("sheet2").Range("b" & i).Value = Worksheets("sheet1").Range("b" & j).Value Exit For End If Next j Next i End Sub
I have the same message
 

Attachments

  • Capture d’écran 2021-04-07 à 23.37.31.png
    Capture d’écran 2021-04-07 à 23.37.31.png
    149.9 KB · Views: 5
Upvote 0
Change both Integer & Byte to Long
 
Upvote 0
Change both Integer & Byte to Long
Thanks for your answer.
When I'm doing it, there is only the english translation of my first sentence that appears for every words I write.

Like :
hommeWhen he asked who had broken the window, all the boys put on an air of innocence.
mangerWhen he asked who had broken the window, all the boys put on an air of innocence.
saisonWhen he asked who had broken the window, all the boys put on an air of innocence.
froidWhen he asked who had broken the window, all the boys put on an air of innocence.

Also, I have to let you know that there might be some duplicates words in the thousands of sentences I have. I just need one sentence and it translation to show up, not all the sentences that contain that word.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

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