Can't find data referred to in an Excel formula - excel

I've inherited a spreadsheet with no instructions.
There is a formula in one of the cells:
=IFERROR(ROUND((SUM('RawData'!C:C)/K21)*24*60*60,0),0)
There are no hidden tabs - so I'm guessing 'RawData' is a named reference of some sort.
Is there any way for me to find out where the data is referred to in 'RawData'?
Thanks for any help, Mark

The worksheet RawData will be a Very Hidden sheet. That means it will not show up in the the normal hide/unhide dialog in Excel.
You will need to use the VBE(Alt-F11) Then Ctr-r if the project Exploreer is not already visible.
Find the sheet in the list click it and change the hidden aspect in the properties of that sheet.

Running the following VBA will also unhide all sheets:
For Each Sht In Application.Worksheets
Sht.Visible = True
Next Sht

Related

On selecting a checkbox in excel the "Tab(s)" should get enabled/disabled or Appear/disappear

Can someone help me with the VBA code
On clicking a checkbox in excel the "Tab(s)" should get enabled/disabled or Appear/disappear
For eg. There is a tab name"Summary" and in Summary sheet1 I have a checkbox. On selecting the checkbox in the sheet1, the sheet 2 should get enabled/disabled or it should appear or disappear
Your help would be much appreciated
Paste this procedure in the code sheet of the worksheet on which you have the CheckBox, for example your Summary sheet.
Private Sub CheckBox1_Click()
Worksheets("Sheet2").Visible = IIf(CheckBox1.Value, xlSheetHidden, xlSheetVisible)
End Sub
There are two references to CheckBox1. That's the name of the check box - in the sub's declaration and the code. If it has another name change both references. Change the name of the worksheet you wish to hide. If you have several check boxes on your worksheet place identical procedures in the code sheet, each referring to another check box.
Note that there are two different kinds of hiding a sheet, xlSheetHidden and xlSheetVeryHidden. Both remove the tab from the bar below the Excel window. However, if you use xlSheetHidden the hidden worksheet can be shown by selecting Unhide from the Format Cells menu. If you choose xlSheetVeryHidden the sheet will not be listed there and the only way to show it again is by access to the VB Editor or code.

Invalid use of property Excel VBA

Sub test()
Worksheets("Sheet1").Range("A1").Value = 20
End Sub
This simple code is giving error when I compile it.
activesheet. works fine.
I want to know whats resulting in an error and how to fix it...
looks like it's not identifying the sheets, workbook etc.
The answer depends on which error you get. There can be 2 issues:
1. Workbook not specified
You have more than one workbook and Excel is looking in the wrong workbook for your sheet named "Sheet1", then you need to specify the workbook.
Workbooks("my-workbook").Worksheets("Sheet1").Range("A1").Value = 20
or if it is in the workbook where the code is running at it is better to use
ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = 20
Note that you should avoid ActiveWorkbook which is not very reliable.
2. Wrong worksheet name
There is no worksheet named Sheet1. Check your worksheet names. Note that there are different ways to specify a worksheet.
Specify by number
Worksheets(1).Range("A1")
This uses the position of the worksheet in the tab bar below the worksheets. Note that is not very reliable because position can easily be changed by moving the tabs around.
Specify by tab name
Worksheets("Sheet1").Range("A1")
This is probably the most common method. The worksheet is specified by its tab name. This is more reliable than by number.
Specify by VBA name
Sheet1.Range("A1")
Here the VBA name of the sheet is used. This name can only be changed in the VB editor and is not visible to the user, and has nothing to do with the tab name. Using this ensures that the VBA code still works on the desired worksheet even if a user changes the tab name of the worksheet.
So if the tab name is Sheet1 its VBA name can be Sheet5 and it can be on position 3 in the tab bar.
Using this example …
Worksheets("Sheet1").Range("A1")
Sheet5.Range("A1")
Worksheets(3).Range("A1")
… are all 3 accessing the exact same worksheet just by different names. So better to use meaningful names (and no numbers) here to not confuse.

How to remove or delete comments in excel worksheet?

As I click on the particular cells in excel, comments appears that disturb me much so I want vba code to delete all the comments instantly in the active worksheet.
All you really need to do is get a range, then clear comments:
Worksheets("MySheet").Activate
ActiveSheet.UsedRange.ClearComments
Does that help?
More Detail
To get the above code to work, there are several approaches. The one I recommend here is:
Open your Excel workbook.
Click the Visual Basic option on the Developer tab. This opens a VBA window with a tree control to the left, which shows the worksheets and workbooks.
Right-click the worksheet and select Insert Module.
In the module window that opens, paste the code I show at the bottom of these instructions.
Save the worksheet as type Excel Macro-Enabled Workbook.
Close the VBA window.
When back in Excel, hit to bring up the Run Macro window. You should see your RemoveComments macro listed. Now click Run and your comments should be removed.
I actually tested this, so it will work if done properly. If it still doesn't work for you, be sure that the worksheet in question is the first worksheet in your workbook. If it isn't, then change Worksheets(1).Activate in your RemoveComments Sub so that it refers to the correct worksheet.
Sub RemoveComments()
Worksheets(1).Activate
ActiveSheet.UsedRange.ClearComments
End Sub
Please see my reply
Sub delete_comments()
Dim i As Range
For Each i In ActiveSheet.UsedRange
i.ClearNotes
Next i
End Sub

Microsoft Excel: Programmatically create a hidden named range

I am told that the Excel object model permits a Range that is not a part of any sheet, yet contains a set of cells and is denoted by a name in the workbook.
Can anyone explain to me how these fit into the Excel object model and how one would go about creating such a thing programatically (either in VBA or .NET source code).
Thanks.
Your question is a little vague, but I'll give it a shot.
Well, as Dave describes, you can give a specific range of cells on a sheet a "Range Name" which you can then refer to programatically, but that doesn't sound like what you are asking.
It sounds like you are asking "is there an abstract RANGE of cells available to be used by VBA code that doesn't literally exist on any worksheet?" The answer to this is no, even named ranges are simply a convenient reference to a real set of cells on a real worksheet.
You can, however, programatically hide a worksheet so that the user doesn't see it, and still work with cells and ranges on that sheet. Just do:
Sheets("Sheet1").Visible = xlSheetHidden
Sheets("Sheet2").Visible = xlSheetVeryHidden
Sheets("Sheet3").Visible = xlSheetVisible
What's "VeryHidden", you ask?
It means that the user can't go to Format, Sheet, Unhide and make the sheet visible.
So if I'm correctly understanding what you want, just programatically hide one of the sheets, then use Dave's technique to create a named reference to a range on this hidden (or VeryHidden) sheet.
That would be a named range. You can reference a selection of cells, and just type a name where it says 'A1' next to the formula bar. That creates a named range that doesn't change.
Alternatively you can create a named range that is based on a formula, and therefore potentially changes as data in the spreadsheet changes. You do this from the 'Define Name' option (which is in the Formulas Ribbon in Office 2010).
Named ranges can be accessed from VBA, and (I'm pretty sure) from .net.
So you'd access the named range from vba like so:
Range["MyNamedRange"]
Yes, there is a NamedRange control in the Microsoft.Office.Tools.Excel namespace in VSTO. This is a host control which is different from the native Range control in the Microsoft.Office.Interop.Excel.Range namespace.

EXCEL 2007 - Need Help creating a button which takes the contents of active worksheet and pastes it in a new worksheet

I have search throughout this site to find a answer to my problem and most of the related solutions are for a far more complicated problem. Here is what I need to have done. I created a simple form in Excel 2007. I am looking for the ability to add a button at the bottom of the form which allows the user to click on the button and copy that worksheet into a new worksheet within the same excel document. Basically just duplicating the active worksheet.
I tried to do it with macros but did not get the desired results, and most of our co-workers still use Excel 2003 so I am not sure if macros will work in the older version of excel. I do not know any VBA which is why I come here in search of help from you all.
So to recap.
One sheet Excel document with a simple form and a command button at the bottom of the active worksheet
The command button "Copy and Paste" that worksheet into a new worksheet within the same excel document
A solution that could work in both Excel 2003 and 2007 if possible. If not, for 2007.
Thanks so much ahead of time for anyone who is willing to help out a Novice Excel User.
Assuming that you know how to add a button here is a simple line of code to duplicate the active worksheet:
Sub Button1_Click()
ActiveSheet.Copy after:=ActiveSheet
End Sub
Maybe something like this (tested in Excel 2003 only):
Dim srcSheet, dstSheet
Set srcSheet = ActiveSheet
Sheets.Add
Set dstSheet = ActiveSheet
srcSheet.Activate
srcSheet.Cells.Select
Selection.Copy
dstSheet.Activate
dstSheet.Cells.Select
ActiveSheet.Paste
You should find this method will work in both Excel 2003 and Excel 2007. In your form, add the following method:
Sub CopySheet(WorkSheetName as String)
Dim WrkSht As Worksheet
Set WrkSht = Sheets(WorkSheetName)
WrkSht.Copy After:=Sheets(WorkSheetName)
Set WrkSht = Nothing
End Sub
From the button click event, call it using:
Sub Button1_Click()
Call CopySheet("WorkSheetToCopyName")
'You could also replace the string name with ActiveSheet if you so wish
End Sub
This will dump a copy of the worksheet in between the current sheet and the next one. I've tested it in Excel 2003 and Excel 2007 and it works in both. It doesn't give the second one a pretty name sadly - it just gets the same name as the source worksheet with (2) put after it.
All the formatting, protection and formulas are copied across too - it's a carbon copy of the first.
I know the question is quite old, but just wanted to note that you (and the user) can do the exact same thing with zero code: right-click on the sheet name at the bottom and select Move or Copy..., then check the Create a copy box and click Ok. Yes, it takes 4 clicks, but it is super easy and avoids code.

Resources