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
Related
I have a code which looks like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Me.sheets("WAM Data").Range("BY5:HW35").Interior.Color = Me.sheets("WAM
Exception").Range("BO7:HM37").Interior.Color
End Sub
But its giving error in code.
What I want to do is, change the cell formatting (color) of "BY5 to HW35" as "BO7:HM37".
If anyone could help that would be great.
You can delete me. and use only Sheets..., or use ActiveWorkbook.Sheets.. to refer to the activeworkbook, or ThisWorkbook.Sheets... to refer to the workbook the macro is run from, or Workbooks("name").Sheets... to choose whichever workbook you want from the ones you have open.
However, your macro will just run on first click of a mouse, regardless where that happens on your spreadsheet, with no conditions add to it... is that what you want to do with your code?
I've uploaded an Excel sheet to our website, but I want to be able to link to a particular row/cell within that sheet, so when people open it, they are taken to that row/cell straight away. Is this possible?
I tried using www.website.co.uk/test.xlsx#Sheet1!A7 but that doesn't appear to work.
I need to be able to link it from a Google Map comment box into a row/cell so it's leaving it fairly limited.
I would have used Google Sheets, but it's blocked by our IT department unfortunately.
As mentioned, for workbooks that are downloaded, you could try a workbook open event. Also provided users can run macros.
Option Explicit
Private Sub Workbook_Open()
If Evaluate("ISREF('Sheet1'!A1)") Then
With ThisWorkbook.Worksheets("Sheet1")
.Activate
.Range("A7").Activate
End With
End If
End Sub
The code above goes in the pane for ThisWorkbook.
I'm trying to create a VBA in Excel 2010 that takes info from another spreadsheet that I'm not allowed to alter and bring it over to the spreadsheet with my macro built in. Here's my code:
Sub BringUpWorkbook()
Workbooks("RITE 1624.xls").Activate
End Sub
I have several VBA books, have visited dozens of sites on the Internet, including those here at stackoverflow.com, and cannot find a reason why I'm receiving the run-time error. The workbook is already open, I've tried adding everything trailing the title, I've tried removing the .xls, I've even did all of the above with in a variable. Any ideas?
Make sure the extension is correct. If it's a excel-2010 file like you indicate, you may need to update your code to reflect the extension of your "RITE 1624" file (e.g. .xlsx for a 2010 Excel workbook, .xlsm for a 2010 Excel macro-enabled workbook, or whatever the extension is.
Sub BringUpWorkbook()
Workbooks("RITE 1624.xlsx").Activate
End Sub
EDIT:
To make sure you have the right name of the workbook, you can print the name of each workbook in an immediate window.
Open up the VBA editor, and then press Ctrl+G to open the Immediate Window (or do View > Immediate window). Then run the following Macro:
Sub OpenWkbkNames()
For Each Workbook In Workbooks
Debug.Print Workbook.Name
Next
End Sub
Note that this will give you the names of all the open workbooks in the same Excel instance as your macro. If your RITE 1624 file is in a separate Excel instance, then the instance that your macro is in will not be able to see that file (and it won't appear in the output of the OpenWkbkNames code above). The simplest way to resolve this is to open all of your necessary files from the Excel instance that contains your macro.
Sub BringUpWorkbook()
Workbooks.Open("RITE 1624.xls").Activate
End Sub
I'm working on an inherited spreadsheet (creation date 1998, or maybe earlier) and need to change the references on a dialog sheet. I can't see the macro in the run macro list, or anything similar, the sheet itself doesn't show up in the VBA project explorer window, which sounds like it could be an Excel 4.0 macro from other questions I've read here. A lot of people suggest rewriting an Excel 4.0 macro from the beginning, but the problem is that I don't actually know what the macro does.
Specifically, the macro is linked to a command button, and when I click on 'Assign macro', the name of the macro is written in the 'Macro name' text box, but it's not actually listed in the drop-down menu. If I try to assign this macro to another command button by typing the same name into the 'Macro name' text box, I get an error that the macro is unavailable.
(Screenshot link: http://imgur.com/HlxvLV2)
I tried using the solution here (Cannot see excel sheet in VBE), and because the sheet I'm interested in is not actually a worksheet, I declared ws as a dialog sheet.
Public Sub TestAccessToXL4MacroSheet()
Dim ws As DialogSheet
Set ws = ThisWorkbook.ActiveSheet ' succeeds
Debug.Print ws.Name ' outputs "Macro1"
Set ws = Worksheets("Macro1") ' fails: "Subscript out of range"
End Sub
The result is that the name of the sheet appears in the immediate window.
(Screenshot link: http://imgur.com/C1L2SQP)
Is this the intended result? I can already see the sheet name as a tab, I want to see the sheet itself in the VBA editor.
XL4 worksheets (your macro1 sheet for example) are not visible in VB IDE.
To view the sheet in Excel right click on one of the visible sheet tabs and from the menu select the command "Unhide...". You can select the macro1 sheet and click "OK".
Alternatively, try
Sub ShowAllSheets()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
sh.Visible = True
Next
End Sub
Then you will need to convert the XL4 code to VBA manually.
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.