VBA Excel 2010 Programming  How to Find If Text is Contained in a Certain String

VBA Excel 2010 Programming How to Find If Text is Contained in a Certain String

Alex C

11 лет назад

45,278 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Grace
Grace - 17.08.2021 16:59

How would you do mulitple strings?

Ответить
Viracocha Lumens
Viracocha Lumens - 07.11.2019 08:10

After some time of running the code, a run time error 1005 occurs. To fix, you need to Set the range method before and after the loop. Also , should be Loop until item_number and not row_number. Define row number as integer and item_number as range.

Ответить
Alex Vasiliev
Alex Vasiliev - 28.08.2019 20:34

Thanks Alex, great stuff!

Just a quick question.
How can I expand the search range not only for column B but for B:K in this line?
item_description = Sheets("Database").Range("B" & row_number)

"B:K" is not working.

Thanks.

Ответить
Олег Олейник
Олег Олейник - 07.06.2019 22:15

Thank you, it really helped me

Ответить
Nitro
Nitro - 06.06.2018 09:01

What if i want to search for 2 text in a string? can I know instr ******* or Instr*********??

Ответить
Rajesh Majumdar
Rajesh Majumdar - 26.04.2018 06:06

Excellent!!!

Ответить
Sahil Mehta
Sahil Mehta - 28.01.2018 10:03

I have struggled to find half decent INSTR function example on web but your example is perfect. I'm so glad you tutorial is without msgbox as msgbox doesn't really help in real world.

Ответить
Jen Batoong
Jen Batoong - 17.04.2016 06:27

What happen when I want to change the find text description? Do O actually have to manually edit the VBA code to change the find "description"!!! Could anyone help!!! Thank you.

Ответить
Joss Lippstreu
Joss Lippstreu - 24.10.2015 07:54

Do you have an example where the number of loops is not known? In your example you set it up so it loops until row 16. What if you are trying to automatize but the amount of rows if never known? Sometimes it is 16 but sometimes it is 3,000.

Ответить
Peter Bom
Peter Bom - 06.02.2014 15:05

Thanks,
I have made a small change to your code

  Set oSht = Sheets("Export")
  LastRow = oSht.Range("A" & Rows.Count).End(xlUp).Row
 
  Row_Number = 1
  Do
  DoEvents
  Row_Number = Row_Number + 1
     Item_Number = Worksheets("Export").Range("A" & Row_Number).Value
     IdCode = Worksheets("Export").Range("F" & Row_Number).Value
    
     If InStr(Item_Number, txtItem.Value) > 0 Then
        lstIdCode.AddItem (IdCode)
     End If
    
  Loop Until Row_Number = LastRow

Ответить
Ch Youness
Ch Youness - 12.06.2013 22:58

thanks

Ответить