Break code if can't find the link of external data

luis0antonio5

New Member
Joined
Jul 30, 2022
Messages
1
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hi, i have a lot of lines a code, there are ranges of some cells. Each one save a position of others books by reference.
VBA Code:
Sheets("test").Range("b3").Value = "='\\server1\DATA\dataset\cabinetes\L31\time\" & year1 & "\" & cmbMes.Value & "\LAST" & "\[L" & "31" & "_" & txtDia.Value & ".xlsx]2do'!R9C6"
    Sheets("test").Range("b4").Value = "='\\server1\DATA\dataset\cabinetes\L31\time\" & year1 & "\" & cmbMes.Value & "\LAST" & "\[L" & "31" & "_" & txtDia.Value & ".xlsx]2do'!R10C6"
    Sheets("test").Range("b5").Value = "='\\server1\DATA\dataset\cabinetes\L31\time\" & year1 & "\" & cmbMes.Value & "\LAST" & "\[L" & "31" & "_" & txtDia.Value & ".xlsx]2do'!R11C6"
..........
......
....
.
.
.
The year, cmbMes, txtDia there are form objects. To complete the path string values.
when it doesn't find the file it breaks the code and shows a file browser window asking to add the file it didn't find, this becomes a loop since I have many lines of code like the ones I put here, so if it doesn't find the file the code does not stop.
1659157139693.png

And i need to press cancel like 100 times to finish it (because I have 100 lines of code like the ones I inserted above)
So I want a way that if it doesn't find the file in the first line, it doesn't search because if it doesn't find it in the first lines, it won't find it in the others.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Do a For loop maybe
You can increment the row number, check the value is not empty
If it is exit sub

Could use a
VBA Code:
For Each cell in RangeToProcess
il might be faster

I have used the .log file approach. In simple terms you check the validity of the file sought, at every step in the loop and if missing write the info to a log file which can be inspected by the user. Can also write to an “output” sheet so the user has the info straight there
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,805
Members
449,262
Latest member
hideto94

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