Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Programmatically set Excel row properties using the Excel Interop

Posted on 2013-02-06
4
Medium Priority
?
298 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

610 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