Solved

Programmatically set Excel row properties using the Excel Interop

Posted on 2013-02-06
4
250 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
Comment Utility
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
Comment Utility
Do you have any sample code for #1?
0
 
LVL 16

Accepted Solution

by:
terencino earned 500 total points
Comment Utility
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
Comment Utility
Thanks... I'll try out the solution this week and let you know.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now