Macro Run only a three lines of code and then stops working without any error messages

John01

New Member
Joined
Oct 12, 2017
Messages
20
I have the code that is working perfectly, but now it doesn't open the code line when comes to open the file from directory. I appreciate some help, thanks in advance. I have the following code:

Sub CENTRAL()

Dim cell3 As Range
Dim FileName As String
Dim CellName As String
Dim Fpath As String
Dim wb As Workbook
Dim SumResult As Double



Workbooks.Open FileName:="C:\Users\SKY\Desktop\Dom\CENTRAL.xlsx"




For Each cell3 In ActiveSheet.Range("A3:A" & Cells(Rows.Count, 1).End(xlUp).row)

finalcolumn = 1 + ActiveSheet.Cells(cell3.row, 14).End(xlToLeft).Column <-- it is executing the code till here

MsgBox finalcolumn <--- to check if it is working

Fpath = ThisWorkbook.Path & "\" <----- from this part macro stops to work
CellName = cell3.Value

FileName = Dir(Fpath & "\*" & CellName & ".xlsx")
Select Case True
Case Trim(cell3.Value) = "Total"
Case Trim(cell3.Value) <> "" And Left (FileName,14) Like "*" & CellName & "*"

Workbooks.Open FileName:=Fpath & FileName
Set wb = ActiveWorkbook
SumResult = WorksheetFunction.Sum(wb.Worksheets(1).Range("B1:B6"))
Totalsum = Totalsum + SumResult

Windows("CENTRAL.xlsx").Activate
Worksheets(1).Range(Cells(cell3.row, finalcolumn), Cells(cell3.row, finalcolumn)).Value = Totalsum
Application.CutCopyMode = False
Application.DisplayAlerts = False

wb.Close



End Select

Next cell3



End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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