how to get multiple value (how get second matching data) - vba

i am working on this code below
i try to get data from another workbooks sheet1
my problem is there are two ” Financial Depth” with different value in workbook sheet1
how i can get them two different cell
example
Financial Depth=10.000
Financial Depth=24.000
this code get first value .(Financial Depth=10.000)......
Sub Balance()
Dim I As Integer
Dim myfile As String
Pathname = “E:\test\”
I = 1
myfile = Dir(Pathname & “*.xls”)
Cells(1, I) = myfile
StartingPoint:
I = I + 1
myfile = Dir
Cells(I, 1) = myfile
If myfile “” Then GoTo StartingPoint
I = I – 1
For K = 1 To I
‘On Error Resume Next
‘ *** workbook name***
Filename = Cells(K, 1)
Workbooks.Open (Pathname & Filename)
‘ *** company name ***
Cells(K, 2) = Workbooks(Filename).Worksheets(“Sheet1″).Cells(1, 1)
‘ *** Financial Depth***
Cells(K, 3) = ” Financial Depth”
For g = 1 To 220
If Workbooks(Filename).Worksheets(“Sheet1″).Cells(g, 1) = ” Financial Depth” Then
Cells(K, 4) = Workbooks(Filename).Worksheets(“Sheet1″).Cells(g, 3)
Exit For
End If
Next g
Workbooks(Filename).Saved = True
Workbooks(Filename).Close
Next k
End Sub

This should work for you
Sub Balance()
Dim I As Integer
Dim myfile As String
Dim m as Integer
m = 4
Pathname = “E:\test\”
I = 1
myfile = Dir(Pathname & “*.xls”)
Cells(1, I) = myfile
StartingPoint:
I = I + 1
myfile = Dir
Cells(I, 1) = myfile
If myfile “” Then GoTo StartingPoint
I = I – 1
For K = 1 To I
‘On Error Resume Next
‘ *** workbook name***
Filename = Cells(K, 1)
Workbooks.Open (Pathname & Filename)
‘ *** company name ***
Cells(K, 2) = Workbooks(Filename).Worksheets(“Sheet1″).Cells(1, 1)
‘ *** Financial Depth***
Cells(K, 3) = ” Financial Depth”
For g = 1 To 220
If Workbooks(Filename).Worksheets(“Sheet1″).Cells(g, 1) = ” Financial Depth” Then
Cells(K, m) = Workbooks(Filename).Worksheets(“Sheet1″).Cells(g, 3)
m = m +1
End If
Next g

Related

How to export a Notes Attachment which is not in the body by using VBA

I hope some of you can help with the code under these text, I can export Attachments which are in the body of an Lotus Notes Mail, but also I need to export them, when they aren't in the body (like "normal" attachments).
Set LNItem = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
int_Anhang = 1
x = 0
Worksheets("Mails").Cells(j, 3).Value = 0
On Error Resume Next
For Each LNAttachment In LNItem.EmbeddedObjects
y = 0
AttPath = ActiveWorkbook.path & "1-Weiterleitung_Mail-Anhang" & y & "-" + LNAttachment.Name
While Dir(AttPath) <> ""
y = y + 1
AttPath = ActiveWorkbook.path & "1-Weiterleitung_Mail-Anhang" & y & "-" + LNAttachment.Name
Wend
LNAttachment.ExtractFile (AttPath)
Worksheets("Mails").Cells(j, 3).Value = Worksheets("Mails").Cells(j, 3).Value + 1
Worksheets("Mails").Cells(j, 7 + x).Value = y & "-" + LNAttachment.Name
x = x + 1
Next
On Error GoTo Fehler
Debug.Print vbNewLine
End If
Can someone help?
My Question in other communities:
ms-office-forum.net
Herber.de
Here are more code:
Dim sess As Object, db As Object, folder As Object, dc As Object, docMemo As Object, docNext As Object, LNItem As Object
Dim memoSenders As Variant, memoAnhang As Variant, memoInhalt As Variant, memoLayout As Variant, LNAttachment As Variant
Dim memoDate As Date, todayDate As Date
Dim mail_Server As String, mail_Datei As String, memoSubject As String, AttPath As String
Dim y As Integer, int_test As Integer
'On Error GoTo Fehler_Notes
On Error GoTo Fehler
Set sess = CreateObject("Notes.NotesSession")
'sess.Initialize ("")
'On Error GoTo Fehler
mail_Server = Worksheets("Daten").Cells(2, 2).Value
mail_Datei = Worksheets("Daten").Cells(2, 3).Value
'Open the mail database in notes
Set db = sess.GetDatabase(mail_Server, mail_Datei)
If db.IsOpen = True Then
'Already open for mail
Else
db.OPENMAIL
End If
int_test = 0
Do While Worksheets("Daten").Cells(i, 6).Value <> ""
Set folder = db.GetView(Worksheets("Daten").Cells(i, 6).Value)
If Worksheets("Daten").Cells(i, 9).Value <> "" Then
todayDate = Worksheets("Daten").Cells(i, 9).Value
Else
Worksheets("Daten").Cells(i, 9).Value = "01.01.2000 00:00"
todayDate = Worksheets("Daten").Cells(i, 9).Value
End If
Set doc = folder.GetFirstDocument
Do Until doc Is Nothing
Set docNext = folder.GetNextDocument(doc)
'Datum des Empfangs
Worksheets("Daten").Cells(29, 2).Value = doc.GetItemValue("DeliveredDate")
memoDate = Worksheets("Daten").Cells(29, 2).Value
int_test = int_test + 1
int_xxx = int_xxx + 1
memoSenders = doc.GetItemValue("From")
memoInhalt = doc.GetItemValue("Body")
memoLayout = doc.GetItemValue("Form")
memoSubject = doc.GetItemValue("Subject")(0)
Worksheets("Mails").Cells(j, 1).Value = i - 2
Worksheets("Mails").Cells(j, 2).Value = memoSenders
Worksheets("Mails").Cells(j, 4).Value = memoInhalt
Worksheets("Mails").Cells(j, 5).Value = memoLayout
Worksheets("Mails").Cells(j, 6).Value = memoSubject
'Prüfen ob Attachments innerhalb der Mail vorhanden sind
Set LNItem = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
int_Anhang = 1
x = 0
Worksheets("Mails").Cells(j, 3).Value = 0
On Error Resume Next
For Each LNAttachment In doc.EmbeddedObjects
y = 0
AttPath = ActiveWorkbook.path & "\01-Weiterleitung_Mail-Anhang\" & y & "-" + LNAttachment.Name
While Dir(AttPath) <> ""
y = y + 1
AttPath = ActiveWorkbook.path & "\01-Weiterleitung_Mail-Anhang\" & y & "-" + LNAttachment.Name
Wend
LNAttachment.ExtractFile (AttPath)
Worksheets("Mails").Cells(j, 3).Value = Worksheets("Mails").Cells(j, 3).Value + 1
Worksheets("Mails").Cells(j, 7 + x).Value = y & "-" + LNAttachment.Name
x = x + 1
Next
On Error GoTo Fehler
Debug.Print vbNewLine
End If
Call doc.PutInFolder(Worksheets("Daten").Cells(6, 3).Value)
Call doc.MarkRead
Call doc.RemoveFromFolder(Worksheets("Daten").Cells(i, 6).Value)
j = j + 1
Set doc = docNext
Loop
Worksheets("Daten").Cells(i, 9).Value = CStr(Format(Now, "MM/DD/YYYY hh:mm"))
i = i + 1
Loop
If int_test <> 0 Then
i = 3
ReadNotesEmail i, j
End If
int_error = 0
Exit Sub
Regards
NotesDocument has also a property EmbeddedObjects.
You can use it this way:
For Each LNAttachment In doc.EmbeddedObjects
...
Next
I've try to make the code from Duston work in Excel VBA:
Set Item = Doc.GetFirstItem("$file")
If LCase(Item.Name) = "$file" Then
Set FileItem = Item
FileName = FileItem.Values(0)
Set Object = Doc.GetAttachment(FileName)
AttPath = ActiveWorkbook.path & "\01-Weiterleitung_Mail-Anhang\" & "1" & "-"
' extract the file ..
Call Object.ExtractFile(AttPath & FileName)
End If
My code produce no error and the script goes into the If-Case, but nothing happens. (The "Filename" is empty)
check for File name and you can get the embededobject
this is the java code:
String path="";
Vector fileName= session.evaluate("#AttachmentNames", document);
for (int i = 0; i < fileName.size(); i++) {
EmbeddedObject embeddedObject =
document.getAttachment(fileName.get(i));
embeddedObject .extractFile(path+fileName.get(i));
}
Also check for items named $File. Some sample code is located in this link:
http://www.richardcivil.net/archives/157
In particular:
If Lcase( item.Name ) = "$file" Then
' get the filename ...
Set FileItem = Item
FileName = FileItem.Values(0)
Set Object = sourceDoc.GetAttachment( FileName )
' extract the file ..
Call object.ExtractFile( tempDir & FileName )
' upload the file ..
Set newObject = attachmentBody.EmbedObject( object.Type, "", tempDir & FileName )
' kill the file ..
Kill tempDir & FileName
End If

Loop Through files in a folder and paste filename onto spreadsheet

I am totally new to VBA, looking for tips or hints to solve this question.
I am trying to loop through all the files in a folder and trying to split the filename into three parts that are separated by underscore and then paste those into a spreadsheet. After that, pivot it and count how many files there are in a new sheet.
For example, Filename : CA_File_20170810.txt
So it looks like this:
**IPA TYPE DATE Filename Filepath**
CA File 20170810
*IPA, Type, Date,filename, filepath are columns headers in excel.
Here is what I have in my code so far
Sub LoopingThroughFiles()
Dim f As String
Dim G As String
Dim File As Variant
Dim MyObj As Object
Dim MySource As Object
Dim FileName As Variant
Dim TypeName As Variant
Cells(1, 1) = "IPA"
Cells(1, 2) = "TYPE"
Cells(1, 3) = "DATE"
Cells(1, 4) = "FILENAME"
Cells(1, 5) = "FILEPATH"
Cells(2, 1).Select
f = Dir("C:\Users\kxc8574\Documents\VBA_Practice\")
G = Dir("C:\Users\kxc8574\Documents\VBA_Practice\")
If Right(f, 1) <> "\" Then
f = f + "\"
Cells(2, 1).Select
Do While Len(f) > 0
IpaName = Left(f, InStr(f, "_") - 1)
ActiveCell.Formula = IpaName
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
Do While Len(G) > 0
TypeName = Mid(G, InStr(G, "_") + 1, InStr(G, "File_") - InStr(G, "_") - 1)
ActiveCell.Formula = TypeName
ActiveCell.Offset(1, 0).Select
G = Dir()
Loop
End If
End Sub
I am missing a lot of things, not sure how to really continue. This code gives me an error "invalid procedure call" when it reaches the G = Dir()
Thanks for your help !!!
First, paste the text under "Explanation" into A1 of a worksheet. Then paste the code under "Code" into a module. Make sure the workbook is in the same directory as your .txt files. Then, run the macro. See animated gif for the result.
"Explanation"
This workbook contains a macro which will
1) Make a new sheet in this workbook named "Combined"
2) Open a copy of each .txt file located in the same directory as this workbook
3) extract the text between "_" characters
4) place the separated text into columns
5) count the number of .txt files processed
Note: Any sheet named "Combined" in this Workbook will be deleted
"Code"
Option Explicit
Sub CombineFiles()
Dim theDir As String, theFile As String
Dim sh As Worksheet, wk As Workbook, newSheet As Worksheet
Dim r As Range, parts() As String
Dim i As Long, s As String
Dim Done As Boolean, numFiles As Integer
Const ext = ".txt"
Err.Clear
theDir = ThisWorkbook.Path
'explain what program does
Worksheets("Program").Select
For i = 1 To 7
s = s & Cells(i, 1) & vbCr & vbCr
Next i
s = s & vbCr
s = MsgBox(s, vbYesNoCancel, "What this macro does")
If s <> vbYes Then End
For Each sh In Worksheets
If sh.Name = "Combined" Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
Next
Set newSheet = ThisWorkbook.Sheets.Add
newSheet.Name = "Combined"
'Loop through all files in directory with ext
s = Dir(theDir & "\*" & ext)
Set r = Range("A1")
r = "IPA"
r.Offset(0, 1) = "Type"
r.Offset(0, 2) = "Date"
r.Offset(0, 3) = "filename"
r.Offset(0, 4) = "filepath"
While s <> ""
numFiles = numFiles + 1
parts = Split(s, "_")
Set r = r.Offset(1, 0)
For i = 0 To 2
r.Offset(, i) = Replace(parts(i), ".txt", "")
Next i
r.Offset(, 3) = s
r.Offset(, 4) = theDir & "\" & s & ext
s = Dir()
Wend
MsgBox (numFiles & " files were processed.")
End Sub
Untested but should give you some idea:
Sub LoopingThroughFiles()
Const FPATH As String = "C:\Users\kxc8574\Documents\VBA_Practice\"
Dim f As String, i As Long, arr, sht As Worksheet
Set sht = ActiveSheet
sht.Cells(1, 1).Resize(1, 5).Value = _
Array("IPA", "TYPE", "DATE", "FILENAME", "FILEPATH")
f = Dir(FPATH & "*.txt") '<< only txt files
i = 2
Do While f <> ""
'split filename on underscore after replacing the ".txt"
arr = Split(Replace(f, ".txt", ""), "_", 3)
sht.Cells(i, 1).Resize(1, UBound(arr) + 1).Value = arr
sht.Cells(i, 4).Value = f
sht.Cells(i, 5).Value = FPATH
f = Dir() '<< next file
i = i + 1
Loop
End Sub
Untested but perhaps something like this??
Sub HashFiles()
Dim MyDir As String, MyIPA As Variant, MyType As Variant, MyDate As Variant, i As Integer, oFile As Object, oFSO As Object, oFolder As Object, oFiles As Object
MyDir = "C:\Users\kxc8574\Documents\VBA_Practice\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(MyDir)
Set oFiles = oFolder.Files
ReDim MyIPA(1 To oFiles.Count)
ReDim MyType(1 To oFiles.Count)
ReDim MyDate(1 To oFiles.Count)
i = 1
For Each oFile In oFiles
MyIPA(i) = Split(oFile.Name, "_")(0)
MyType(i) = Split(oFile.Name, "_")(1)
MyDate(i) = Split(oFile.Name, "_")(2)
i = i + 1
Next
Range("A2").Resize(UBound(MyIPA) + 1, 1) = Application.Transpose(MyIPA)
Range("B2").Resize(UBound(MyType) + 1, 1) = Application.Transpose(MyType)
Range("C2").Resize(UBound(MyDate) + 1, 1) = Application.Transpose(MyDate)
End Sub

excel vba finding with like or regex

I'm writing a VBA program.
I have a problem with finding this string [BLOCKED] in one column
For j = 0 To 4
For i = 2 To lastrow
If Cells(i, 12).Value = groupnames(j) And Cells(i, 8).Value Like "*" & "[BLOCKED]" & "*" Then
groupsum(j) = groupsum(j) + 1
End If
Next i
Next j
The problem is I have 96 cells for this string but the program found 500 how can I do this to going work?
Thanks for help
The syntax of your Like operation is incorrect. Use:
... Like "*[[]BLOCKED]*"
[...] is a Character class. So, the way you have it written in your question, it will find any single character in the set of BLOCKED. That is not what you want, apparently.
To match the [ character, you enclose it within a character class, as I have shown. To match the ] character, it must be outside of a character class.
here is my code
Sub blocked()
Dim SfileUsers As String
Dim path As String
Dim pathread As String
Dim sFileread As String
Dim lastrow As Long
Dim keres() As Variant
Dim groupadd() As String
Dim groupnames(4) As String
Dim groupsum(4) As Long
path = "C:\Users\uids9282\Desktop\"
SfileUsers = "Users.xlsx"
Workbooks.Open path & SfileUsers
Dim hossz As Long
hossz = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
ReDim keres(hossz)
ReDim groupadd(hossz)
For i = 2 To hossz
keres(i) = Sheets(1).Cells(i, 2).Value
groupadd(i) = Sheets(1).Cells(i, 4).Value
Next i
'fájlmegnyitás
pathread = "C:\Users\uids9282\Desktop\20170703\"
sFileread = "open.xml"
If Dir(pathread & sFileread) = sFileread Then
Workbooks.Open pathread & sFileread
lastrow = Workbooks(sFileread).Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Else
MsgBox ("Nincs ilyen nevű excel táblázat. Kérem próbálkozzon újra")
End If
'groupok hozzáadása a fájlhoz
Dim user As String
For j = 2 To hossz
For i = 2 To lastrow
user = Trim(Cells(i, 5).Value)
If user = keres(j) Then
Cells(i, 12).Value = groupadd(j)
End If
Next i
Next j
'group szummázása és átírása
ThisWorkbook.Activate
For i = 2 To 6
groupnames(i - 2) = Cells(i, 1).Value
Next i
Workbooks(sFileread).Activate
For j = 0 To 4
For i = 2 To lastrow
If Cells(i, 12).Value = groupnames(j) And Cells(i, 8).Value Like "*[[]BLOCKED[]]*" Then 'itt van benne a hiba!! groupsum(j) = groupsum(j) + 1
End If
Next i
Next j
ThisWorkbook.Activate
For j = 2 To 6
Cells(j, 4).Value = groupsum(j - 2)
Next j
Workbooks(SfileUsers).Close SaveChanges:=False
Workbooks(sFileread).Close SaveChanges:=True
End Sub
this is my excel file where i want to searching

Subscript out of range error in VBA

I am trying to import FDF files(can be multiple) with VBA. When I run my code I got Subscript out of range error.
I know that the error suggests the worksheet it is looking for does not exist but I don't believe the code below actually defines the worksheet name which is probably the cause of the problem?
Can I have assistance in where, and what, code to insert to address this error? This is my code what I tried:
Sub FDFImport()
Dim OutSH As Worksheet
Dim Fname As Variant, f As Integer
Fname = Application.GetOpenFilename("FDF File,*.fdf", 1, "Select One Or More Files To Open", , True)
For f = 1 To UBound(Fname)
Open Fname(f) For Input As #1
Do While Not EOF(1)
Line Input #1, myvar
arr = Split(myvar, Chr(10))
arr2 = Split(arr(4), "/V")
If InStr(1, myvar, "(Contact)") > 0 Then
Set OutSH = Sheets("Contact")
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 1 To 8
placer = InStr(1, arr2(i), ")")
OutSH.Cells(outrow, i).Value = Left(arr2(i), placer - 1)
Next i
Else
Set OutSH = Sheets("NoContact")
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 1 To 12
placer = InStr(1, arr2(i), ")")
OutSH.Cells(outrow, i).Value = Left(arr2(i), placer - 1)
Next i
End If
Loop
Close #1
Sheets("Contact").Cells.Replace what:="(", replacement:=""
Sheets("NoContact").Cells.Replace what:="(", replacement:=""
Next f
End Sub
This is just a guess based on what you have posted but give this a try
Sub FDFImport()
Dim OutSH As Worksheet
Dim Fname As Variant, f As Integer
Dim myvar, arr, arr2, outrow, i, placer
Fname = Application.GetOpenFilename("FDF File,*.fdf", 1, "Select One Or More Files To Open", , True)
If VarType(Fname) = vbBoolean Then
Exit Sub
End If
For f = LBound(Fname) To UBound(Fname)
Open Fname(f) For Input As #1
Do While Not EOF(1)
Line Input #1, myvar
arr = Split(myvar, Chr(10))
arr2 = Split(arr(4), "/V")
If InStr(1, myvar, "(Contact)") > 0 Then
Set OutSH = Sheets("Contact")
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 0 To 7
placer = InStr(1, arr2(i), ")")
OutSH.Cells(outrow, i).Value = Left(arr2(i), placer - 1)
Next i
Else
Set OutSH = Sheets("NoContact")
outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
For i = 0 To 11
placer = InStr(1, arr2(i), ")")
OutSH.Cells(outrow, i).Value = Left(arr2(i), placer - 1)
Next i
End If
Loop
Close #1
Sheets("Contact").Cells.Replace what:="(", replacement:=""
Sheets("NoContact").Cells.Replace what:="(", replacement:=""
Next f
End Sub
When you Split the array will be 0 based. Meaning you need loop through the array from 0 to X. When you are looping arr2 you have For i = 1 To 8 my guess is it should be For i = 0 To 7 you are doing the same for arr I have changed this is my answer.

Opening another workbook on a save event (VBA)

So, I have the code below in my "Thisworkbook" Module. I need it to run whenever the user saves the workbook. The code opens another workbook and transfers data into the new workbook.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Exit Sub
On Error Resume Next
Dim Mas_loc As String
Mas_loc = "C:\Users\J03800\Documents\All Folders\Berry\MasterBerry.xlsx"
Dim n As Integer
Dim m As Integer
Dim x As Integer
Dim y As Integer
Dim PartNumber As String
Dim CageCode As String
Dim PartCage As String
Dim MI As Integer
Dim ChildWB As Workbook
Dim MasterWB As Workbook
Dim IsMatch As Boolean
Dim ChiMain As Worksheet
Dim MasMain As Worksheet
Set ChildWB = ActiveWorkbook
Set MasterWB = Workbooks.Open(Mas_loc)
Set ChiMain = ChildWB.Sheets("Main")
Set MasMain = MasterWB.Sheets("Main")
n = Application.CountA(ChiMain.Range("B:B")) + 1
m = Application.CountA(MasMain.Range("B:B")) + 1
ChildWB.Activate
For x = 3 To n
PartNumber = ChiMain.Cells(x, "B").Value
CageCode = ChiMain.Cells(x, "A").Value
CSMC = ChiMain.Cells(x, "J").Value
CMC = ChiMain.Cells(x, "L").Value
MassObj = ChiMain.Cells(x, "E").Value
ComObj = ChiMain.Cells(x, "H").Value
If Len(PartNumber) > 0 Then
If Len(CageCode) > 1 Then
PartNumber = "-" & Replace(Replace(PartNumber, CageCode & "-", ""), "-" & CageCode, "")
PartCage = "Cage-" & CageCode & "-" & PartNumber
Else
PartCage = "NoCage-" & PartNumber
End If
Else
PartCage = ""
End If
On Error GoTo NewPart
MatchAddress = Application.WorksheetFunction.Match(PartCage, MasMain.Range("K1:K" & m + 20), 0)
contin:
On Error Resume Next
If Len(CSMC) > 0 And Len(Replace(CSMC, "?", "")) = Len(CSMC) And Len(MasMain.Cells(MatchAddress, "E").Value) = 0 Then
MasMain.Cells(MatchAddress, "E").Value = CSMC
End If
If Len(CMC) > 0 And Len(Replace(CMC, "?", "")) = Len(CMC) And Len(MasMain.Cells(MatchAddress, "H").Value) = 0 Then
MasMain.Cells(MatchAddress, "H").Value = CMC
End If
If Len(MassObj) > 0 And Len(Replace(MassObj, "?", "")) = Len(MassObj) And Len(MasMain.Cells(MatchAddress, "C").Value) = 0 Then
MasMain.Cells(MatchAddress, "C").Value = MassObj
End If
If Len(MassObj) > 0 And Len(Replace(MasMain.Cells(MatchAddress, "C").Value, ComObj, "")) = MasMain.Cells(MatchAddress, "C").Value Then
MasMain.Cells(MatchAddress, "G").Value = MasMain.Cells(MatchAddress, "G").Value & Chr(10) & ComObj
End If
Next
MasterWB.Close SaveChanges:=True
Exit Sub
NewPart:
On Error Resume Next
m = m + 1
MatchAddress = m
MasMain.Cells(MatchAddress, "A").Value = ChiMain.Cells(MatchAddress, "A").Value
MasMain.Cells(MatchAddress, "B").Value = ChiMain.Cells(MatchAddress, "B").Value
MasMain.Cells(MatchAddress, "K").Value = PartCage
GoTo contin
End Sub
The problem seems to be that is is not opening MasterWB. As, when it bugs out, MasterWB is both not open and according to the code equal to nothing. What should I change?
Your code block looks fine - assuming the path specified in Mas_loc is accurate.
What errors are you getting when it "bugs out"?
Have you stepped through the code to see what is happening?
I would comment out the On Error Resume Next statement to stop masking any runtime errors.
I made the sub not private, then it worked