Solved

Programmatically set Excel row properties using the Excel Interop

Posted on 2013-02-06
4
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

742 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