Loop Through Worksheets, Some Protected, To Apply Macro
Jan 28, 2009
Cycle through all sheets in a workbook performing the following:Store worksheet protection state (bSheetProtection)... execute code ...Restore worksheet protectionI cannot seem to locate a way to save a worksheet's protection state in a variable.
View 5 Replies
ADVERTISEMENT
Aug 5, 2008
I am creating a series of macros for a workbook, and at the beginning of each macro I unprotect all sheets and at the end of each macro I protect the sheets once more. The issue I am having is that even with these macros in place, I continue to receive an Excel alert message saying:
"The cell or chart that you are trying to change is protected and therefore read-only. To modify a protected cell or chart, first remove protection using the Unprotect Sheet command (Review tab, Changes group). You may be prompted for a password."
The macro will then run. Everything works as it should, but I do not want this error message to pop up. I have tried inserting
Application.DisplayAlerts = False
into the code, but it does not stop the message.
View 9 Replies
View Related
Jun 20, 2009
I am using DSUM functions which result in having to have an extra row beneath each of the DSUM formula rows (for the criteria arguments)
The code below checks for color coding and then populates 1 or a 0 in the database for the DSUM formulas
Im trying to optimize the code so that it runs faster. how can i code to skip the rows that do not contain data?
other optimization / best practices that you recommend are appreciated!
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Goto errorout:
If Not Intersect(Target(1, 1), Range("j3")) Is Nothing Then
Application. ScreenUpdating = False
For Each rcell In Range("j11:n731")
If rcell.Value = 1 Then
rcell.Interior.ColorIndex = 37
Else
rcell.Interior.ColorIndex = xlNone
End
View 8 Replies
View Related
Dec 2, 2009
I need to run the below code on all work sheets:
Sub Remove_Duplicate()
On Error Resume Next
Columns("a").Insert
With Range("b1", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
.Formula = "=If(CountIf(B$1:B1,B1)=1,"""",False)"
.SpecialCells(-4123, 4).EntireRow.Delete
End With
Columns("a").Delete
End Sub
Basically I have lots of worksheets and I want to remove the duplicates in column B for each work sheet with a duplicate entry...
View 9 Replies
View Related
Oct 11, 2007
I have a workbook in which I have 31 sheets. I've also recorded a macro that works great when I run it on one sheet, but it comes up with an error when I try to run it on grouped worksheets. I searched Google, and a few articles I saw said that in order to run a macro on grouped sheets, you have to use loops. I don't know if this is true, but I don't know how to run loops anyway, so. I want to run the macro on 30 of the 31 sheets. I was going to put the code in, but when I did that my post didn't work, so I'm thinking there might be a limit on the length of a post.
View 5 Replies
View Related
Apr 17, 2014
I have the following macro:
[Code] .....
So right now the macro is run in every single worksheet in the workbook. Unfortunately, it appears the TRIM function erases formulas in cells. I want this macro to apply only to certain worksheets. Say the worksheets i want the macro to run on are named A1-A100.
View 5 Replies
View Related
Apr 29, 2014
I am using this RDB code to send a fixed range to a fixed recipient in the body of an email, but I would like to set it to run for all worksheets.
[Code] .........
View 5 Replies
View Related
Aug 11, 2009
I am having trouble creating a macro for an excel file I am working on. I do not have much experience writing macros, so I apologize for any confusion. I have created a simplified version of the file I am attempting to write a macro for and attached it to my post here.
At this point it would be helpful for you to open up the attached file so that you can understand my explanation.
Basically what I want the macro to do is:
1. Match up "Product" on Wksht(Input) with "Product" on Wksht(Data).
2. Copy the "Usage per ton" and "Dollars per ton" values corresponding to the given product from Wksht(Input) to Wksht(Data) for the correct month. (The user will manually enter the month, ie "August 09" into Wksht(Input) each month when he runs the macro.)
++The color fills will not exist on my finished macro. I only put them there to illustrate the values that will be copied and pasted.
I want the macro to be written with Loop commands so that it will check to be sure the product number matches with the given location for pasting the data values. I should also note I use PasteSpecial_Values because of the formulas in the cells on Wksht(Input).
View 12 Replies
View Related
Jul 19, 2012
I have a Database and every entry in the database has its own corresponding sheet with the data in a more viewer-friendly format. I want to assign a macro to a button to loop through all the sheets, copy the cells and paste to the database (to update the database).
Also, nothing prevents the user from deleting the sheets or mixing them. So is there a way to take the reference number from the database in column B, search for the corresponding sheet which has the reference number in cell B3 and then update it accordingly.
Code:
Sub Button19_Click()
Dim WS_Count As Integer
Dim I As Integer
[Code]...
View 1 Replies
View Related
Aug 31, 2007
I have this macro and all I want to do is apply it to every page of my worksheet with a loop and can't find what kind of loop I need:
Sub format()
' Keyboard Shortcut: Ctrl+r
'
ActiveCell. Offset(-37, 0).Rows("1:1").EntireRow.Select
Selection.Copy
ActiveCell.Offset(37, 0).Rows("1:1").EntireRow.Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Range("A1:K37").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
View 3 Replies
View Related
Nov 4, 2013
I have a workbook that contains, say, 50 worksheets: the first two worksheets summarise the data and are static in that they don't move position. However, the next four worksheets contain certain data for any given month. Each time a new month comes along, say, November, I insert four new worksheets after the two static ones as a result October's four worksheets are simply moved down the line in terms of worksheet order.
I need a macro to refer to the first six worksheets only (not the other tabs). I opted for index referencing for each worksheet, ie one - six. Now within these six worksheets in any given month, I need to sort the data by a certain column. The problem: in sheets 1,4,5 and 6 I need to rank by column E, but in sheets 2 and 3 I need to rank by column C. I have stepped through the code, which works for sheets 3-6, but doesn't seem to refer to sheets 1-2.
Sub WorksheetLoop()
'
' Loop through an indexed number of worksheets; _
' & this ensures that the worksheet range is dynamic _
' and is able to adjust when new sheets are added/removed, etc.
'
'Dim ws As Worksheet
Dim i As Long
Dim ws As Worksheet
[code]....
View 2 Replies
View Related
Jun 30, 2009
I have a module, which lists, by date, the number of instances of certain words as defined at the top of the column.
Anyway, this works fine - it operates on all sheets of a certain name type:
View 10 Replies
View Related
Nov 20, 2007
I recorded a macro in an Excel Workbook which contains 65 worksheets (--this is something received on a quarterly basis for which I have no control). The macro is successful within the workbook created however, a new quarter's data may or maynot have some of the referenced worksheets. 64.9 Waiv - 1 may exists and the others (2, 3, 4, etc) not. The macro fails and prompts for Debug if a worksheet does not exist.
Sheets("64.9 Waiv - 1").Select
Sheets("64.9 Waiv - 2").Select
Sheets("64.9 Waiv - 3").Select
Sheets("64.9 Waiv - 4").Select
Sheets("64.9 Waiv - 5").Select
Sheets("64.9 Waiv - 6").Select
Sheets("64.9 Waiv - 7").Select
Sheets("64.9 Waiv - 8").Select
Sheets("64.9 Waiv - 9").Select
Sheets("64.9 Waiv - 10").Select
Is it possible to alter the macro to look for and only invoke the code if a worksheet past 1 were to exist?
This is what I am requesting the macro do:
Sheets("64.9 Waiv - 1").Select
Range("B9").Select
ActiveWindow.FreezePanes = True
ActiveWindow.SmallScroll ToRight:=5
Range("J8").Select ...............
View 9 Replies
View Related
Jan 16, 2009
Just need to delete some hyperlinks in column A on 50+ worksheets. Thought a loop through all the worksheets would do it. Only works on active sheet. Forgive my ignorance, don't really even know where it goes, once it works - module or workbook?
View 2 Replies
View Related
Aug 10, 2009
I'm trying to perform the same process to all the worksheets in my workbook. This is the code I have now, but it will only apply to the single active worksheet:
View 2 Replies
View Related
Apr 2, 2012
I used VBA codes to apply different passwords for different worksheets in a single excel workbook. They worked fine. Then i applied a password to the VBA code itself through the VBA project properties. Also worked.
But my problem is that, if any one enters a wrong password to open any of the worksheets, the VBA will open an error message window and when "end" option is clicked, the VBA code will open without any prompt for the password.Thus the entire purpose is defeated.
View 9 Replies
View Related
Aug 20, 2008
I Need the outline/group feature to work on a protected workbook with over 200 sheets, meaning a macro to cover the entire workbook not just a single sheet. This macro should travel with the workbook as it will be on many different peoples PC's
Private Sub Workbook_Open()
Dim cSheet As Integer
Dim tSheet As Worksheet
On Error Resume Next
cSheet = 1
Set tSheet = Worksheets(cSheet)
While Err.Number = 0
Call wbProtect(tSheet)
cSheet = cSheet + 1
Set tSheet = Worksheets(cSheet)
Wend
Err.Number = 0
End Sub..........................
View 2 Replies
View Related
Aug 29, 2006
Is it possible to keep the sort icon available on a worksheet which is protected? I have issued a spreadsheet to colleagues which contains formulas so I have protected it, but I have now been informed that they need to be able to sort the data according to a ref number.
I thought of using code (which I'm not very good at) and used some from another excel document, but couldn't get it to work...the code was ....
View 9 Replies
View Related
Aug 3, 2006
I have the following code that should open all EXCEL workbooks in a
specified path, and unprotoect any password-protected worksheets to allow
for Link Updates, then close the workbook after password protecting it.
sub UpdateAllLinks()
Dim vLinkSources
Dim iLinkSource As Integer
Dim AnySheet As Worksheet
sPath = " C:Documents and SettingsShaneMy DocumentsHarcourt
Assessmentspassword"
sName = Dir(sPath & "*.xls")
do while sName <> ""...............
View 9 Replies
View Related
Oct 4, 2007
I've looked through this wonderful sight and haven't found one close to my project. I am a bit rusty on VB programming. I am working on workbook that contains multiple worksheets. Each worksheet is hidden and is accessible with a login and password so that only a specific user can access. My question is: How do I modify this so that the manager can open the workbook and view ALL worksheets without having to enter the login name and password for all of his users? Any help would be great. Thank you!!
Below is what I have so far: ....
View 9 Replies
View Related
Apr 30, 2003
Is there a way to password protect a document AND still allow for a user to expand or collapse columns?
Currently, it appear that when a worksheet is password protected, one cannot expand or collapse a column.
View 9 Replies
View Related
Oct 5, 2006
I have a sheet that I protect but i use the below code so that I can still use my gouping '+' or '-' symbols to hide/unhide rows.
ws.Protect Password:="PASSWORD", userinterfaceonly:=True
ws.EnableOutlining = True
This is ok but When close the workbook and reopen it, my sheet becomes fully protected and i cant use the group icons. Can anyone either suggest better code or a way to initilise the workbook to act in this way when it loads up. For Reference Below is my full
Sub ProtectAll()
Dim ws As Worksheet
sSheet = Control.Name
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case sSheet1
Case Else
ws.Protect Password:="PASSWORD", userinterfaceonly:=True
ws.EnableOutlining = True
End Select
Next ws
End Sub
View 2 Replies
View Related
Dec 8, 2009
I am trying to set up a macro that hides certain columns of data in an automated spreadsheet that I don't need. How do I make the macro that hides the columns apply to all spreadsheets that are open except for the one I am in?
View 9 Replies
View Related
May 11, 2009
I am trying to record a macro that edits a rows data, and simply copies it to a new cell further along on the same row,. but i then want it to move to the next row down, and apply the same macro to that run, and continue until there is no data in the last row,. How do I get the macro to continue to the end of the data.
View 5 Replies
View Related
Apr 8, 2008
I have a number of sheets in my workbook which I'd like to run the same code against. Rather than calling each by name is there a way to define each sheet as an array number and use that to loop through?
For this example we'll use Sheet1, Sheet2, Sheet3 and Sheet4
View 9 Replies
View Related
Dec 22, 2006
I have a simple macro with a loop which selects sheets in a workbook. sheets are named "Sheet 1" to Sheet 6". Two sheets are missing (say sheet 3 and sheet 5). The On Error code works when the macro tries to find sheet 3 but crashes on the second error (when it tries to find sheet 5).
Sub SelectSheet()
For i = 1 To 6
MySheet = "Sheet" & i
On Error Goto 10
Sheets(MySheet).Select
10
Next i
End Sub
View 3 Replies
View Related
Jul 30, 2008
I've made a spreadsheet at home on Excel 2007 which has up to 5 Conditional Formatting rules per cell which works fine. The problem is when I save as 97-2003 version to send to work, the old version of Excel only supports 3 rules as you know, is there a way of applying 4 or 5 rules when specific text is populated in a cell on the old version of Excel?
View 14 Replies
View Related
Oct 3, 2009
I have a worksheet that I am always adding sheets to by duplicating an already existing tab. The tab ,"Current Invoice", is nested between sheets called "first" and "last". All duplicate sheets will also be nested between the "First" and "Last" tabs. What I would like to do is have a macro that affects all tabs between the "First" and "Last" only, even when the bookend tabs are hidden.
This is what I've started with.
HTML Sheets(Array("First", "Last")).Select
ActiveWindow.SmallScroll Down:=18
Range("U29:U190").Select
Selection.Copy
Range("AA29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("W29:W190").Select
Application.CutCopyMode = False
Selection.Copy
Range("AB29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
View 4 Replies
View Related
Jan 18, 2014
i want to apply a macro for all sheets that start with "MCC ENTRY" and "MCC EXIT"
i.e. MCC ENTRY 1, MCC ENTRY 2, MCC ENTRY 3, etc. & MCC EXIT 1, MCC EXIT 2, MCC EXIT 3, ETC.
View 1 Replies
View Related
May 14, 2007
I poked around and found a macro to highlight the active cell, but I want to limit it to be active only for range A1:A37. Any ideas? I put in the Set OldCell = Range("A1:A37"), but all it does is turn every cell you pick blue and it stays that way, so I'm not sure how to limit it.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Static OldCell As Range
Set OldCell = Range("a1:a37")
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 8
Set OldCell = Target
End Sub
View 9 Replies
View Related