Solved

Programmatically set Excel row properties using the Excel Interop

Posted on 2013-02-06
4
277 Views
Last Modified: 2013-07-24
We have an Excel spreadsheet that is populated from data in a database using a program we developed in C# .

Everything works fine but now we need to be able to store a key identifier (that we format and create) for each row.

Is there a way to apply this key "value" to a property at the row level so the users do not see our key value anywhere in the spreadsheet?  or via some other method?

We want to avoid using a hidden column since there is a chance the user could make the column visible, thus potentially changing this key value.
0
Comment
Question by:jkanisut
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:terencino
ID: 38863572
Excel doesn't have anything at the row level that might suit I'm afraid, would be great if it did. A couple of other options:
1. Put the key value in one of the columns, set cell protection only for that range to locked and hidden, format as ;;;  then use sheet-level protection only for that range and possibly a password to prevent the key value being both seen and deleted.
2. Put the key value in a separate sheet, linked to the relevant row on the main data sheet, then make that key sheet VeryHidden
3. Add the key value to a comment in the cells on one column, then hide the comments. This is less obvious than a hidden column, and harder to change en masse, but not as secure.
Hope that helps
...Terry
0
 
LVL 1

Author Comment

by:jkanisut
ID: 38863874
Do you have any sample code for #1?
0
 
LVL 16

Accepted Solution

by:
terencino earned 500 total points
ID: 38863924
Sure I put the key values in A2:A21 in this sheet, and protected the sheet, just recorded the macro as I did it. Can't see, modify or delete any cell in that range. There is no password so you can just unprotect it and click on the cell to see what is in there
...Terry

Sub Protection()
    Cells.Locked = False
    Cells.FormulaHidden = False
    Range("A2:A21").Locked = True
    Range("A2:A21").FormulaHidden = True
    Range("A2:A21").NumberFormat = ";;;"
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
        :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
        AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
        AllowUsingPivotTables:=True
End Sub

Open in new window

Protection.xlsm
0
 
LVL 1

Author Comment

by:jkanisut
ID: 38873967
Thanks... I'll try out the solution this week and let you know.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question