+ Reply to Thread
Results 1 to 3 of 3

How to allow users to add/delete rows/cloumns in sheets with macros.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    13

    How to allow users to add/delete rows/cloumns in sheets with macros.

    Hi excel gurus,

    I have a sheet with macros that allows users to fill in data from columns F10 to O10 from row 10 to 54.
    Column P will then make some computations based on the inputs from col F to O.
    Row 55 will also make some computation based on inputs from row 10 to 54.
    How to I modify the code below to allow users to either add/delete columns and rows such that it does not fowl up the computations?
    The computation does not have to be at column P or at row 55, they can be dynamic and change depending on how many rows and columns the users delete/add.

    A little background on what the code does. From Column F to O, the code UNLOCKS the columns only if user inputs date in Cell 3 of that particular column.
    Example. Column F is locked from F10 to infinity at the start. Only when user inputs date into F3 does the cells F10:F54 is unlocked for user to input data.
    This goes on until column O. I want users to be able to add more columns, or delete ones they don't need.

    I hope I'm clear...

    Thanks Thanks.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    Application.EnableEvents = False
    For Each c In Target
        If Not IsError(c) And Not Intersect(c, Range("F3:O3")) Is Nothing Then
            If c.Value = "" Then
                Sheets(ThisWorkbook.ActiveSheet.Name).Unprotect Password:="1234" 'change to your actual password
                Range(Cells(10, c.Column), Cells(54, c.Column)).ClearContents
                Range(Cells(10, c.Column), Cells(54, c.Column)).Locked = True
                Sheets(ThisWorkbook.ActiveSheet.Name).Protect Password:="1234"
            Else
                Sheets(ThisWorkbook.ActiveSheet.Name).Unprotect Password:="1234" 'change to your actual password
                Range(Cells(10, c.Column), Cells(54, c.Column)).Locked = False
                Sheets(ThisWorkbook.ActiveSheet.Name).Protect Password:="1234"
            End If
        End If
    Next c
    Application.EnableEvents = True
    End Sub
    Last edited by damienchew; 03-13-2014 at 12:13 AM. Reason: Redefine Problem

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Lightbulb Re: How to allow users to add/delete rows/cloumns in sheets with macros.

    Hi Damienchew,
    Is Row 55 last row in your worksheet, i.e. without the user inserting any new row(s)? If so, you may use the following to get a handle on the row immediately after the current last row; and then execute your computation there.

    ThisWorkbook.Worksheets("Name_of_the_worksheet").Cells(Rows.Count, <Insert_Column_Number>).End(xlUp).Offset(1, 0)
    Warm regards,
    Jewel

  3. #3
    Registered User
    Join Date
    01-05-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: How to allow users to add/delete rows/cloumns in sheets with macros.

    Thanks Jewel,

    Not realy what I am looking for.
    Maybe I should refocus. How do I rework the code,such that the column range is dynamic instead of being fixed to column F to column O, such that when user adds or deletes columns from F to O the code still works as it should for the new column range.

    Thanks.
    Damien.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Multiplying rows and cloumns
    By skochar in forum Excel General
    Replies: 8
    Last Post: 11-21-2006, 06:51 AM
  2. [SOLVED] In a protected worksheet allow users to delete rows
    By Jason Trivett in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. In a protected worksheet allow users to delete rows
    By Ian in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 06:05 AM
  4. In a protected worksheet allow users to delete rows
    By Jason Trivett in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  5. In a protected worksheet allow users to delete rows
    By Jason Trivett in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-12-2005, 05:05 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