SOLVED

Excel Visual Basic help

%3CLINGO-SUB%20id%3D%22lingo-sub-3374103%22%20slang%3D%22en-US%22%3EExcel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374103%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22%22%3EHello.%20Was%20wondering%20if%20you%20could%20help%20me%20with%20a%20workbook%20I'm%20trying%20to%20create.%20The%20purpose%20is%20to%20track%20employees%20with%20numbers%3B%20on%20the%20first%20sheet%20(Form)%20someone%20will%20scan%20their%20number%2C%20it%20will%20then%20get%20stored%20on%20a%20second%20sheet%20with%20time%20stamp.%20The%20next%20time%20the%20number%20is%20scanned%20it%20finds%20the%20previous%20entry%20then%20adds%20another%20time%20stamp%20in%20the%20column%20next%20to%20the%20first.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELike%20this%20coding%20but%20I%20need%20the%20%22barcode%22%20entered%20on%20one%20sheet%20with%20the%20data%20on%20another%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20inout()%3C%2FP%3E%3CP%3EDim%20barcode%20As%20String%3C%2FP%3E%3CP%3EDim%20rng%20As%20Range%3C%2FP%3E%3CP%3EDim%20rownumber%20As%20Long%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebarcode%20%3D%20Worksheets(%22Sheet1%22).Cells(2%2C%202)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet%20rng%20%3D%20Sheet1.Columns(%22a%3Aa%22).Find(What%3A%3Dbarcode%2C%20_%3C%2FP%3E%3CP%3ELookIn%3A%3DxlFormulas%2C%20LookAt%3A%3DxlWhole%2C%20SearchOrder%3A%3DxlByRows%2C%20_%3C%2FP%3E%3CP%3ESearchDirection%3A%3DxlNext%2C%20MatchCase%3A%3DFalse%2C%20SearchFormat%3A%3DFalse)%3C%2FP%3E%3CP%3EIf%20rng%20Is%20Nothing%20Then%3C%2FP%3E%3CP%3EActiveSheet.Columns(%22a%3Aa%22).Find(%22%22).Select%3C%2FP%3E%3CP%3EActiveCell.Value%20%3D%20barcode%3C%2FP%3E%3CP%3EActiveCell.Offset(0%2C%201).Select%3C%2FP%3E%3CP%3EActiveCell.Value%20%3D%20Date%20%26amp%3B%20%22%20%22%20%26amp%3B%20Time%3C%2FP%3E%3CP%3EActiveCell.NumberFormat%20%3D%20%22m%2Fd%2Fyyyy%20h%3Amm%20AM%2FPM%22%3C%2FP%3E%3CP%3EWorksheets(%22Sheet1%22).Cells(2%2C%202)%20%3D%20%22%22%3C%2FP%3E%3CP%3EElse%3C%2FP%3E%3CP%3Erownumber%20%3D%20rng.Row%3C%2FP%3E%3CP%3EWorksheets(%22Sheet1%22).Cells(rownumber%2C%201).Select%3C%2FP%3E%3CP%3EActiveCell.Offset(0%2C%202).Select%3C%2FP%3E%3CP%3EActiveCell.Value%20%3D%20Date%20%26amp%3B%20%22%20%22%20%26amp%3B%20Time%3C%2FP%3E%3CP%3EActiveCell.NumberFormat%20%3D%20%22m%2Fd%2Fyyyy%20h%3Amm%20AM%2FPM%22%3C%2FP%3E%3CP%3EWorksheets(%22Sheet1%22).Cells(2%2C%202)%20%3D%20%22%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20If%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3374103%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374120%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374120%22%20slang%3D%22en-US%22%3EThe%20main%20problem%20is%20the%20active%22%22%20part%20I%20think.%20I%20don't%20know%20any%20other%20way.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374321%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374321%22%20slang%3D%22en-US%22%3EOr%20how%20can%20I%20edit%20this%20code%20so%20when%20a%20previously%20scanned%20number%20is%20scanned%20again%20it%20will%20find%20the%20row%20and%20add%20a%20timestamp%20one%20cell%20to%20the%20right%20of%20the%20first%20timestamp%20it%20did%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20Intersect(Target%2C%20Range(%22D16%22))%20Is%20Nothing%20Then%20Exit%20Sub%3CBR%20%2F%3EIf%20Target%20%3D%20%22%22%20Then%20Exit%20Sub%3CBR%20%2F%3EDim%20w2%20As%20Worksheet%2C%20nr%20As%20Long%3CBR%20%2F%3EWith%20Application%3CBR%20%2F%3E.EnableEvents%20%3D%20False%3CBR%20%2F%3E.ScreenUpdating%20%3D%20False%3CBR%20%2F%3ESet%20w2%20%3D%20Sheets(%22Sheet2%22)%3CBR%20%2F%3EWith%20w2%3CBR%20%2F%3Enr%20%3D%20w2.Cells(w2.Rows.Count%2C%20%22A%22).End(xlUp).Row%20%2B%201%3CBR%20%2F%3EIf%20nr%20%3D%202%20And%20w2.Range(%22A1%22)%20%3D%20vbEmpty%20Then%20nr%20%3D%201%3CBR%20%2F%3Ew2.Range(%22A%22%20%26amp%3B%20nr)%20%3D%20Target.Value%3CBR%20%2F%3Ew2.Range(%22B%22%20%26amp%3B%20nr)%20%3D%20Now()%3CBR%20%2F%3Ew2.Range(%22B%22%20%26amp%3B%20nr).NumberFormat%20%3D%20%22mm%2Fdd%2Fyyyy%20hh%3Amm%3Ass%20AM%2FPM%22%3CBR%20%2F%3Ew2.Columns(%22A%3AB%22).AutoFit%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3ETarget.Clear%3CBR%20%2F%3E.EnableEvents%20%3D%20True%3CBR%20%2F%3E.ScreenUpdating%20%3D%20True%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20Sub%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374443%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374443%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESub%20inout()%0A%20%20%20%20Dim%20ws1%20As%20Worksheet%0A%20%20%20%20Dim%20ws2%20As%20Worksheet%0A%20%20%20%20Dim%20barcode%20As%20String%0A%20%20%20%20Dim%20rng%20As%20Range%0A%20%20%20%20Dim%20rownumber%20As%20Long%0A%20%20%20%20Set%20ws1%20%3D%20Worksheets(%22Form%22)%0A%20%20%20%20'%20***%20Change%20Sheet2%20to%20the%20name%20of%20the%20other%20sheet%20***%0A%20%20%20%20Set%20ws2%20%3D%20Worksheets(%22Sheet2%22)%0A%20%20%20%20barcode%20%3D%20ws1.Range(%22B2%22).Value%0A%20%20%20%20Set%20rng%20%3D%20ws2.Range(%22A%3AA%22).Find(What%3A%3Dbarcode%2C%20LookIn%3A%3DxlValues%2C%20LookAt%3A%3DxlWhole)%0A%20%20%20%20If%20rng%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20Set%20rng%20%3D%20ws2.Range(%22A%22%20%26amp%3B%20ws2.Rows.Count).End(xlUp).Offset(RowOffset%3A%3D1)%0A%20%20%20%20%20%20%20%20rng.Value%20%3D%20barcode%0A%20%20%20%20End%20If%0A%20%20%20%20rownumber%20%3D%20rng.Row%0A%20%20%20%20Set%20rng%20%3D%20ws2.Cells(rownumber%2C%20ws2.Columns.Count).End(xlToLeft).Offset(ColumnOffset%3A%3D1)%0A%20%20%20%20rng.Value%20%3D%20Now%0A%20%20%20%20rng.NumberFormat%20%3D%20%22m%2Fd%2Fyyyy%20h%3Amm%20AM%2FPM%22%0A%20%20%20%20ws1.Range(%22B2%22).ClearContents%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374449%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374449%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BTrying%20to%20get%20end%20product%20to%20look%20something%20like%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Scan%20barcode%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371638i6361E5A33BC6C5E1%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22form.PNG%22%20alt%3D%22Scan%20barcode%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EScan%20barcode%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Data%20sheet%201st%20scan%22%20style%3D%22width%3A%20618px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371639i11D08DAEE2ECD440%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22data1.PNG%22%20alt%3D%22Data%20sheet%201st%20scan%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EData%20sheet%201st%20scan%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Data%20sheet%202nd%20scan%22%20style%3D%22width%3A%20657px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371640i9CAA825203EEB66C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22data2.PNG%22%20alt%3D%22Data%20sheet%202nd%20scan%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EData%20sheet%202nd%20scan%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374450%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374450%22%20slang%3D%22en-US%22%3EADP%20%3D%20barcode%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374469%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374469%22%20slang%3D%22en-US%22%3EMy%20bad%20it%20works!%20So%20on%20sheet1%20I%20just%20tie%20the%20macro%20to%20a%20button.%20Your%20awesome!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374517%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374517%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BCan%20I%20have%20two%20versions%20of%20this%20workbook%3F%20One%20where%20employees%20can%20only%20see%2Faccess%20sheet1%20Form%3B%20and%20one%20where%20managers%20see%2Faccess%20both%20sheets%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374520%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374520%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDo%20you%20really%20want%20two%20versions%20of%20the%20workbook%2C%20or%20one%20workbook%20where%20only%20some%20people%20can%20view%20the%20second%20sheet%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374521%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374521%22%20slang%3D%22en-US%22%3EOne%20workbook%20where%20only%20some%20can%20view%20second%20sheet%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3374733%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374733%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20Visual%20Basic%20Editor%2C%20double-click%20ThisWorkbook%2C%20then%20copy%20the%20following%20code%20into%20it%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EPrivate%20Sub%20Workbook_Open()%0A%20%20%20%20Worksheets(%22Form%22).Activate%0A%20%20%20%20Worksheets(%22Sheet2%22).Visible%20%3D%20xlSheetVeryHidden%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EChange%20%3CEM%3ESheet2%3C%2FEM%3E%20to%20the%20name%20of%20the%20other%20sheet.%3C%2FP%3E%0A%3CP%3E%26nbsp%3BThis%20hides%20the%20second%20sheet%2C%20while%20it%20can%20only%20be%20unhidden%20using%20VBA%2Cnot%20from%20the%20Excel%20interface.%3C%2FP%3E%0A%3CP%3EIn%20the%20same%20module%20that%20contains%20the%20inout%20macro%2C%20create%20a%20new%20macro%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESub%20UnhideSheet()%0A%20%20%20%20If%20InputBox(%22Enter%20password%22%2C%20%22Activate%20other%20sheet%22)%20%3D%20%22mypassword%22%20Then%0A%20%20%20%20%20%20%20%20With%20Worksheets(%22Sheet2%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20.Visible%20%3D%20xlSheetVisible%0A%20%20%20%20%20%20%20%20%20%20%20%20.Activate%0A%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20MsgBox%20%22Incorrect%20password.%20Access%20denied.%22%2C%20vbCritical%0A%20%20%20%20End%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EChange%20%3CEM%3Emypassword%3C%2FEM%3E%20to%20the%20password%20you%20want%20to%20use%20(it%20should%20be%20more%20secure%20than%20%3CEM%3Emypassword%3C%2FEM%3E!)%2C%20and%20change%20%3CEM%3ESheet2%3C%2FEM%3E%20to%20the%20name%20of%20the%20other%20sheet.%3C%2FP%3E%0A%3CP%3ESwitch%20back%20to%20Excel.%3C%2FP%3E%0A%3CP%3ECreate%20a%20new%20button%20on%20the%20Form%20sheet%2C%20and%20assign%20the%20UnhideSheet%20macro%20to%20it.%20Set%20its%20caption%20to%20%22Show%20other%20sheet%22%20or%20something%20like%20that.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETell%20the%20managers%20who%20will%20need%20to%20access%20the%20second%20sheet%20the%20password%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWarning%3A%20VBA-savvy%20users%20will%20be%20able%20to%20view%20the%20code%20and%20thus%20the%20password.%3C%2FP%3E%0A%3CP%3EIf%20you%20would%20like%20to%20prevent%20that%2C%20you%20have%20to%20lock%20the%20VBA%20project%20for%20viewing%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22S1434.png%22%20style%3D%22width%3A%20414px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371649iB431A3E61861849A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22S1434.png%22%20alt%3D%22S1434.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3375050%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3375050%22%20slang%3D%22en-US%22%3EThank%20you%20so%20much!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3384607%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3384607%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%20A%20quick%20edit%2C%20I%20added%20another%20sheet%20to%20hide%20then%20unhide%20with%20password.%20Will%20the%20one%20password%20unhide%20both%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385120%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385120%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat's%20up%20to%20you.%20If%20all%20persons%20who%20will%20be%20allowed%20to%20unhide%20one%20of%20the%20sheets%20will%20also%20be%20allowed%20to%20unhide%20the%20other%20one%2C%20you%20can%20use%20one%20macro%2C%20with%20one%20password.%3C%2FP%3E%0A%3CP%3EBut%20if%20employee%20A%20should%20only%20be%20allowed%20to%20unhide%20sheet%20A%20and%20employee%20B%20to%20unhide%20sheet%20B%2C%20use%20two%20different%20macros%2C%20with%20two%20different%20passwords.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385223%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385223%22%20slang%3D%22en-US%22%3EIm%20not%20sure%20how%20to%20add%20the%20third%20sheet%20to%20unhide%20with%20password%20like%20the%20other%20sheet.%3CBR%20%2F%3Ep.s.%20Is%20it%20possible%20to%20duplicate%20the%20macro%20of%20the%20%22Form%22%20where%20one%20puts%20a%20number%20in%20a%20box%20which%20when%20entered%20logs%20it%20on%20the%202nd%20sheet%20with%20timestamp%20(like%20we%20have%20it)%20and%20another%20number%20in%20a%20different%20box%20on%20the%20Form%20sheet%20that%20just%20requires%20it%20to%20send%20the%20number%20to%20another%20cell%20within%20the%20same%20row%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385259%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385259%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BSo%20on%20the%20Form%20sheet%20one%20would%20enter%2012345%20in%20a%20cell%20then%20in%20another%20type%20ML%2010%3B%20press%20the%20%22Enter%22%20macro%20button%3B%20values%20are%20logged%20in%20the%202nd%20sheet%20%22Data%22%20and%20the%20Form%20cell%20clear%20back%20to%20blank.%20Then%20when%20they%20do%20it%20a%20second%20time%20it%20searches%20for%20the%20previous%20row%20to%20logged%20data%2C%20the%20ML%2010%20value%20should%20end%20up%20in%20cell%20next%20to%20each%20other.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22edit.PNG%22%20style%3D%22width%3A%20992px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F372241i57B0D8069A88A8E0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22edit.PNG%22%20alt%3D%22edit.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385660%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385660%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20would%20cause%20problems%20if%20you%20entered%2012345%20more%20than%202%20times%20since%20there%20is%20room%20for%20only%202%20timestamps...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385684%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385684%22%20slang%3D%22en-US%22%3Eis%20it%20possible%2012345%20%3A%20timestamp%20%3A%20_____%20%3A%20ML10%20then%20the%20second%2012345%20just%20finds%20row%20and%20inputs%20the%20second%20timestamp%3F%20Or%20is%20all%20based%20on%20offset%20relative%20to%20the%2012345%20cell%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385687%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385687%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat's%20possible%2C%20but%20what%20should%20happen%20if%20you%20enter%2012345%20a%20third%20time%2C%20intentionally%20or%20by%20accident%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385730%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385730%22%20slang%3D%22en-US%22%3EWell%20I%20guess%20Im%20thinking%20employee%20bring%20defective%20equipment%20%22ML%2010%22%20to%20a%20manger%20switch%20it%20out%20for%20another%20unit%20then%20manager%20goes%20in%20to%20the%20work%20book%20and%20manually%20edits%20the%20employee%20assigned%20unit%2C%20so%20the%20employee%20is%20only%20%22scanning%22%20in%20their%20number%20twice.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385731%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385731%22%20slang%3D%22en-US%22%3ETruth%20be%20told%20Excel%20is%20haunting%20my%20dreams.%20Just%20trying%20to%20get%20a%20semi-working%20prototype%20together.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3385961%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3385961%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20the%20attached%20simple%20demo.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3386021%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3386021%22%20slang%3D%22en-US%22%3EYes%20that%20will%20work%20until%20I%20can%20figure%20out%20a%20better%20solution.%20Perhaps%20make%20it%20in%20Access%3F%20Regardless%20you%20are%20truly%20the%20best%20hands%20down!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3386038%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Visual%20Basic%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3386038%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390083%22%20target%3D%22_blank%22%3E%40marvel2r%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20done%20in%20Excel%20and%20also%20in%20Access.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello. Was wondering if you could help me with a workbook I'm trying to create. The purpose is to track employees with numbers; on the first sheet (Form) someone will scan their number, it will then get stored on a second sheet with time stamp. The next time the number is scanned it finds the previous entry then adds another time stamp in the column next to the first.

 

Like this coding but I need the "barcode" entered on one sheet with the data on another

 

Sub inout()

Dim barcode As String

Dim rng As Range

Dim rownumber As Long

 

barcode = Worksheets("Sheet1").Cells(2, 2)

 

Set rng = Sheet1.Columns("a:a").Find(What:=barcode, _

LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _

SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

If rng Is Nothing Then

ActiveSheet.Columns("a:a").Find("").Select

ActiveCell.Value = barcode

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = Date & " " & Time

ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"

Worksheets("Sheet1").Cells(2, 2) = ""

Else

rownumber = rng.Row

Worksheets("Sheet1").Cells(rownumber, 1).Select

ActiveCell.Offset(0, 2).Select

ActiveCell.Value = Date & " " & Time

ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"

Worksheets("Sheet1").Cells(2, 2) = ""

 

End If

 

End Sub

23 Replies
The main problem is the active"" part I think. I don't know any other way.
Or how can I edit this code so when a previously scanned number is scanned again it will find the row and add a timestamp one cell to the right of the first timestamp it did?


Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("D16")) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
Dim w2 As Worksheet, nr As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
Set w2 = Sheets("Sheet2")
With w2
nr = w2.Cells(w2.Rows.Count, "A").End(xlUp).Row + 1
If nr = 2 And w2.Range("A1") = vbEmpty Then nr = 1
w2.Range("A" & nr) = Target.Value
w2.Range("B" & nr) = Now()
w2.Range("B" & nr).NumberFormat = "mm/dd/yyyy hh:mm:ss AM/PM"
w2.Columns("A:B").AutoFit


End With
Target.Clear
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
best response confirmed by marvel2r (Occasional Contributor)
Solution

@marvel2r 

Try

Sub inout()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim barcode As String
    Dim rng As Range
    Dim rownumber As Long
    Set ws1 = Worksheets("Form")
    ' *** Change Sheet2 to the name of the other sheet ***
    Set ws2 = Worksheets("Sheet2")
    barcode = ws1.Range("B2").Value
    Set rng = ws2.Range("A:A").Find(What:=barcode, LookIn:=xlValues, LookAt:=xlWhole)
    If rng Is Nothing Then
        Set rng = ws2.Range("A" & ws2.Rows.Count).End(xlUp).Offset(RowOffset:=1)
        rng.Value = barcode
    End If
    rownumber = rng.Row
    Set rng = ws2.Cells(rownumber, ws2.Columns.Count).End(xlToLeft).Offset(ColumnOffset:=1)
    rng.Value = Now
    rng.NumberFormat = "m/d/yyyy h:mm AM/PM"
    ws1.Range("B2").ClearContents
End Sub

@Hans Vogelaar Trying to get end product to look something like this.

 

Scan barcodeScan barcodeData sheet 1st scanData sheet 1st scanData sheet 2nd scanData sheet 2nd scan

ADP = barcode
My bad it works! So on sheet1 I just tie the macro to a button. Your awesome!

@Hans Vogelaar Can I have two versions of this workbook? One where employees can only see/access sheet1 Form; and one where managers see/access both sheets?

@marvel2r 

Do you really want two versions of the workbook, or one workbook where only some people can view the second sheet?

One workbook where only some can view second sheet

@marvel2r 

In the Visual Basic Editor, double-click ThisWorkbook, then copy the following code into it:

Private Sub Workbook_Open()
    Worksheets("Form").Activate
    Worksheets("Sheet2").Visible = xlSheetVeryHidden
End Sub

Change Sheet2 to the name of the other sheet.

 This hides the second sheet, while it can only be unhidden using VBA,not from the Excel interface.

In the same module that contains the inout macro, create a new macro:

Sub UnhideSheet()
    If InputBox("Enter password", "Activate other sheet") = "mypassword" Then
        With Worksheets("Sheet2")
            .Visible = xlSheetVisible
            .Activate
        End With
    Else
        MsgBox "Incorrect password. Access denied.", vbCritical
    End If
End Sub

Change mypassword to the password you want to use (it should be more secure than mypassword!), and change Sheet2 to the name of the other sheet.

Switch back to Excel.

Create a new button on the Form sheet, and assign the UnhideSheet macro to it. Set its caption to "Show other sheet" or something like that.

 

Tell the managers who will need to access the second sheet the password,

 

Warning: VBA-savvy users will be able to view the code and thus the password.

If you would like to prevent that, you have to lock the VBA project for viewing:

S1434.png

Thank you so much!

@Hans Vogelaar  A quick edit, I added another sheet to hide then unhide with password. Will the one password unhide both?

@marvel2r 

That's up to you. If all persons who will be allowed to unhide one of the sheets will also be allowed to unhide the other one, you can use one macro, with one password.

But if employee A should only be allowed to unhide sheet A and employee B to unhide sheet B, use two different macros, with two different passwords.

Im not sure how to add the third sheet to unhide with password like the other sheet.
p.s. Is it possible to duplicate the macro of the "Form" where one puts a number in a box which when entered logs it on the 2nd sheet with timestamp (like we have it) and another number in a different box on the Form sheet that just requires it to send the number to another cell within the same row?

@Hans Vogelaar So on the Form sheet one would enter 12345 in a cell then in another type ML 10; press the "Enter" macro button; values are logged in the 2nd sheet "Data" and the Form cell clear back to blank. Then when they do it a second time it searches for the previous row to logged data, the ML 10 value should end up in cell next to each other.

 

edit.PNG

@marvel2r 

This would cause problems if you entered 12345 more than 2 times since there is room for only 2 timestamps...

is it possible 12345 : timestamp : _____ : ML10 then the second 12345 just finds row and inputs the second timestamp? Or is all based on offset relative to the 12345 cell?

@marvel2r 

That's possible, but what should happen if you enter 12345 a third time, intentionally or by accident?

Well I guess Im thinking employee bring defective equipment "ML 10" to a manger switch it out for another unit then manager goes in to the work book and manually edits the employee assigned unit, so the employee is only "scanning" in their number twice.