excel vba to run a different function based on cell value

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
528
Office Version
  1. 365
Platform
  1. Windows
hi all

i have the below vba code

VBA Code:
Function test() As Boolean
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim MyFile As Variant

ChDrive "C:"
MyFile = Application.GetOpenFilename
If MyFile = False Then
test = False
    Exit Function
  Else
    test = True
    End If


Workbooks.OpenText FileName:=MyFile _
, Origin:=437, StartRow:=1 _
        , DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 1), _
        Array(3, 1), Array(4, 2), Array(5, 1), Array(6, 1), Array(7, 2), Array(8, 2), Array(9, 2), _
        Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 2), Array(15, 1), Array( _
        16, 1), Array(17, 1)), TrailingMinusNumbers:=True
Cells.Select
    Cells.EntireColumn.AutoFit

I would like to add that if the cell value of A1 of the particular file that I'm opening, is blank then it runs a different function and if the cell value in b1 is blank then it runs a third function or a different sub i can split it if needed, the only reason I'm using functions is because if i hit cancel on the open dialog it doesn't error out
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

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