Results 1 to 4 of 4

Can't figure out what I'm doing wrong - VBA help

Threaded View

  1. #1
    Registered User
    Join Date
    03-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Can't figure out what I'm doing wrong - VBA help

    I'm a noob at VB, and totally self taught. The following code is for a time sheet, which automatically fills in the shift based on the date. There are 4 possible schedule patterns, Day Shift, Night Shift, Daywork and Daywork Training. It looks on a hidden sheet that has the shift pattern in the cells and the shift type represented by:

    D = Day shift
    N= Night Shift
    DW = Daywork (8 hr Mon-Fri)
    DT = Daywork Training

    They all work except for the final one (Daywork Training), which fills in ALL the slots on the timesheet, as if all shifts were selected. I'm pulling my hair out, because it's the exact same IF-THEN format as the other schedules, but it doesn't work. Any help is appreciated. (I know there are probably more efficient ways to write this code, bbut like I said, I'm a self taught noob)

    I hope I explained this well enough.






    Sub PlaceShiftHours()
    
    Dim ShiftLetter, DatePos
    
    On Error Resume Next
    
    If Cells(4, 19).Value = "Letter A" Then ShiftLetter = 1
    If Cells(4, 19).Value = "Letter B" Then ShiftLetter = 2
    If Cells(4, 19).Value = "Letter C" Then ShiftLetter = 3
    If Cells(4, 19).Value = "Letter D" Then ShiftLetter = 4
    If Cells(4, 19).Value = "Letter A/B" Then ShiftLetter = 5
    If Cells(4, 19).Value = "Letter C/D" Then ShiftLetter = 6
    If Cells(4, 19).Value = "Daywork" Then ShiftLetter = 7
    If Cells(4, 19).Value = "Training" Then ShiftLetter = 8
    
    ClearCells
    
    
     For X = 5 To 18
       WorkDate = Cells(14, X).Value
       DatePos = ((WorkDate - 41617) Mod 28) + 1
      
    
       If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "D" Then
          ActiveWorkbook.Worksheets("TimeSheet").Cells(28, X).Value = 8
          ActiveWorkbook.Worksheets("TimeSheet").Cells(29, X).Value = 4
          ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
       End If
      
       If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "N" Then
          ActiveWorkbook.Worksheets("TimeSheet").Cells(32, X).Value = 8
          ActiveWorkbook.Worksheets("TimeSheet").Cells(33, X).Value = 4
          ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
       End If
     
       If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "DW" Then
          ActiveWorkbook.Worksheets("TimeSheet").Cells(16, X).Value = 8
          ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
       End If
       
       If ActiveWorkbook.Worksheets("Shifts").Cells(DatePos, ShiftLetter).Value = "DT" Then
          ActiveWorkbook.Worksheets("TimeSheet").Cells(24, X).Value = 8
          ActiveWorkbook.Worksheets("TimeSheet").Cells(15, X).Value = [VLOOKUP(TimeSheet!I3, OperatorArray, 4)]
       End If
    
    Next X
    
    End Sub
    Last edited by tedkord; 02-03-2015 at 07:09 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 08-28-2014, 08:01 PM
  2. Troubleshoot my formula that I can't figure out what is wrong with
    By smockpuv in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-15-2013, 10:59 AM
  3. HELP, i am having an error and cant figure out whats wrong with my vba
    By basmienis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2012, 06:55 AM
  4. cant figure out what I'm doing wrong or missing...
    By soundengineer in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-25-2007, 07:40 PM
  5. Cell displaying wrong figure
    By tcapewell in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 07:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1