Solved

Programmatically set Excel row properties using the Excel Interop

Posted on 2013-02-06
4
290 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

705 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