InStr to do things of file contains string

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
Here is what I am currently building:

Sub Macro1()


Dim ER As Long
ER = ThisWorkbook.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Dim Cell As Range
Dim CriteriaRange As Range
Set CriteriaRange = ThisWorkbook.ActiveSheet.Range("A2:A" & ER)
For Each Cell In CriteriaRange
If InStr(1, Cell.Value, "H04C", vbTextCompare) > 0 Then 'Searches for H04C'
File_name = ActiveCell.Value 'Minor issues here... I am unsure if my active cell would be the correct cell...Any input? I think my intention is clear'
Path_Name = ActiveCell.Offset(columnOffset:=5).Value 'Assuming the Active cell is correct, offset 5 and that is where the file is located'
Workbooks.Open Filename:=File_name 'Open the Workbook'
End If
Next Cell

End Sub

I am trying to search for a String in a list of file names on my active worksheet. When it finds that string (for instance, "H04C"), it opens all of the files and does things. Anyone have any input?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try changing ActiveCell to Cell
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hey Fluff. Question. I am using this to parse information from lots of sheets and put it onto 1 sheet. I want to copy information starting on row 6 columns A through K for all of the files. I don't think "ActiveSheet.Range("A6:K") will work. How do I specify a limit so I don't copy B1-B5, C1-C5, D1-D5, etc.
 
Upvote 0
As this is a completely different question, please start a new thread.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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