Long VB If statement need shortened

autigers

Board Regular
Joined
Oct 9, 2005
Messages
139
Is there a better way to set this code up ?
Code:
Private Sub Workbook_Open()

On Error GoTo TheEnd

Sheets("Config").Activate
If Environ("username") = ("ouaaye") Then
        With Sheets("Config")
        TheAns = FindColumn(.Name, Environ("username"))
        ans = Cells(2, TheAns)
        MsgBox "The password to access the VB environment is  " & ans & "     Figure you earned it !!"
End With
End If
If Environ("username") = ("OWNER") Then
        With Sheets("Config")
        TheAns = FindColumn(.Name, Environ("username"))
        ans = Cells(2, TheAns)
        MsgBox "The password to access the VB environment is  " & ans & "                             :O)"
End With
End If
If Environ("username") = ("inakgr") Then
        With Sheets("Config")
        TheAns = FindColumn(.Name, Environ("username"))
        ans = Cells(2, TheAns)
        MsgBox "The password to access the VB environment is  " & ans & "                             :O)"
End With
End If
If Environ("username") = ("appjcl") Then
        With Sheets("Config")
        TheAns = FindColumn(.Name, Environ("username"))
        ans = Cells(2, TheAns)
        MsgBox "The password to access the VB environment is  " & ans & "                             :O)"
End With
End If
If Environ("username") = ("inabgi") Then
        With Sheets("Config")
        TheAns = FindColumn(.Name, Environ("username"))
        ans = Cells(2, TheAns)
        MsgBox "The password to access the VB environment is  " & ans & "                             :O)"
End With
End If
Application.ScreenUpdating = False
 
The only code I have that this is applicable to is for the end of shift codes.
1) Exports hours into record of Daily Prod from DataInput sheet
2) Inserts record from frm Daily production detail to DailyProd
3) Builds Memo section for a turnover
4) Exports from DailyProd to Sheet "DailyNote" in report form
5) Exports Shift data for Lotus Notes automated copy picture/paste/send
6) Exports Daily Prod data to Access database via
Code:
Dim wrkJet As WorkSpace
  Dim dbsJtest As Database
  Dim rstJtest As Recordset
  Dim sht1 As Worksheet

So you can see there are quite a number of areas that would reuire tailoring to suit the If in each code set ......

As for permissons .... they are set via
Code:
Environ("username")
Your thoughts ?
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hmm, looks like a pretty big project in the making.

I'd sketch out a flow diagram of what you want to happen from when the workbook is first opened and then take it step by step coding each part as you go.

Do all these 6 things happen for each opening of the workbook ?
If so, I'd probably set up each task as a stand alone Public Sub in module1 and then pass to the Sub all the info it needs to know what to do, where to get its data and where to send it etc.

That way each task is self contained and can be worked on till its right. Your main code then would be just logic and questions/answers to determine the info to pass to each Sub

Its raining cats and dogs here (very noisy) so my apologies if I have got the wrong end of the stick

cheers

Mark
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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