Results 1 to 17 of 17

Thread: [RESOLVED] Excel Conundrum

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [RESOLVED] Excel Conundrum

    Hi All,

    I'm trying to get this code to work, I'm stuck on the first hurdle, I'm trying to get the below to lock each cell after a user enters a value, but I can't get it to work.

    The only ranges a user would need to fill in once are:

    C8 - F12
    C23 - F27
    C38 - F42
    C53 - F57

    Code:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    On Error GoTo enditall
    Application.EnableEvents = False
    If Target.Cells.Column = 2 Then
    ActiveSheet.Unprotect Password:="justme"
    N = Target.Row
    If Excel.Range("B" & N).Value <> "" Then
    Excel.Range("B" & N).Locked = True
    End If
    End If
    enditall:
    ActiveSheet.Protect Password:="justme"
    Application.EnableEvents = True
    End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    You lost me...

    Forget the code at the moment... Tell me what do you exactly want to do?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    haha!! Sorry!

    Okay, Well i have an Excel sheet where I enter my daily working hours, IE: 07:30 - 12:30 - 13:30 - 18:30

    Management in their infinite wisdom think this is a great idea and want everyone to do it, but are worried the peoples will use this to fiddle the numbers (somehow) so I tried to get a code that locks each cell after editing, I tried to upload the excel sheet to attach to the post but, due to format and size it can't be attached, it would explain things alot easier, sorry.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    that locks each cell after editing
    What if the user has made a mistake in typing. How would the user amend it?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    I know, daft an't it! I think they would then appoint an administrator (not liable to bribes, counts me out!) that would be able to amend the typos/mistakes and reprotect.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    You still want to go ahead with it?

    If yes, then my next question... If the first user enters and locks the sheet then how will the 2nd user enter data?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Yeah, I think it could be a good idea, and could save alot of paper,

    Techincally, the sheet consists of 4 weeks worth of daily times, and is only meant to be filled in by one user each day, the above code was good because it wouldn't lock the cell unless a value has been entered.

    Ideally the sheet would be a template for which users would open and then save for themselves each month.

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    Ok let me upload a sample for you... Could you tell me which version of excel are you using?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Ah your awesome! many thanks it's 2003 SP3

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Would you need a copy of the Sheet, I'll try and get a chopped down version, so you can see what I'm on about..

    Please see the attached... I've had to change the file extention to .doc from .xls so i could post it.
    Attached Files Attached Files
    Last edited by Kubull; Jun 11th, 2010 at 10:13 AM.

  11. #11
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    Ok I was busy creating a separate sample for you but it's good that you gave a sample of your own for me to work on...

    So now what you want (correct if I am wrong) is

    The moment user fills up Cell C8 and D8 then those cells should be locked. Similarly when the user fills up C9 and D9 then those cells should get locked... Am I right in my understanding?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Yeah, although its more the individual cells rather then the pairs.

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    Something like this? I have just worked for the range C8 to F12

    The moment you enter any value in the above range, it will get locked...

    Before you paste this code ensure that
    1) The locked property of C8 to F12 is False.
    2) The sheet is protected using the password "justme"

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim r As Long, c As Long
    
        '~~> Required as it will give error if it encounters a protected cell    
        On Error Resume Next
        r = Target.Previous.Row
        c = Target.Column
        On Error GoTo 0
        
        Select Case c
        Case 3, 4, 5, 6 '<~~ Column C to F
            Select Case r
            Case 8, 9, 10, 12 '<~~ Row 8 to 12
                If Len(Trim(Cells(r, c))) = 0 Then Exit Sub
                ActiveSheet.Unprotect Password:="justme"
    
                Cells(r, c).Locked = True
                
                ActiveSheet.Protect Password:="justme"
            End Select
        End Select
    End Sub
    Edit:
    I am leaving for the day (I am in the office and don't have internet at home for the time being). Will check on this thread tom
    Last edited by Siddharth Rout; Jun 11th, 2010 at 11:11 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Thanks again, I'll test it when I get home, but from the looks of it, it looks good!

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Thanks again Coolsid! the Code works really well, I'm just putting the final touches to the template before submitting to the 'heavy's'. I'm having slight issue with a userform I've created for it, I'm used to Word and userforms "Selection.Typetext...blah!) but it's different in Excel, I'm trying to get the below to work, but it's not liking it. any help?


    Code:
    Private Sub cmdOkay_Click()
    Dim ws As Worksheet
    Set ws = Worksheets("FlexiHours")
    
    ws.Cells(B3, 2).Value = Me.txtname.Value
    ws.Cells(E3, 5).Value = Me.txtdepartment.Value
    ws.Cells(J3, 10).Value = Me.txtbalance.Value
    ws.Cells(B8, 2).Value = Me.txtdate.Value
    
    End Sub

  16. #16
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Excel Conundrum

    There are two ways you can reference a cell for example if you want to refer to cell B10 then you can do it like this

    Code:
    Range("B10")
    or

    Code:
    Cells(10,2) '<~~ 10 is the row number and 2 is the column number
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: Excel Conundrum

    Thanks again, "Range("") worked in the end! your a star, if any royalities come out of this (Government department... doubt it!) 50-50? lol more like 70 - 30! thanks again!

Posting Permissions

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



Click Here to Expand Forum to Full Width