Loop To Select Different Sheets
May 2, 2006
I've put the following code together;
Sub RemoveStars()
Application. ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("Sheet1").Select
Cells.Replace What:=" *** ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Sheets("Sheet2").Select
Cells.Replace What:=" *** ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Sheets("Summary").Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
There are more sheets that this is run on, but I am sure you get the idea. I guess that this can be done using a loop, I would prefer to code the sheet names in, there are 5 in total.
View 6 Replies
ADVERTISEMENT
Mar 22, 2012
I have a list of worksheets that I want to select from a list.
Region 1
Region 2
Region 3
etc....
These sheets are in a workbook that contains other non Region sheets.
How do I select all of them without hardcoding the sheet names?
View 5 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
Feb 26, 2012
I have a workbook that updates from external source and creates sheets depending on a cell range.
I have put tab 1 and tab 0 on either end of where the new sheets will be inputted, will never know how many sheets
What i need to happen is if someone fills in "complete" in A7 in my "summary" sheet then the values in row 6 in all the other sheets get hardcoded. This needs to happen from A7 down to A26, so A8 = complete then copy row 7 etc
This is what i have so far
I get compile error here ........Sheets(ArrSh(1)).Activate
Also need it to work for all the other rows.
Sub hardcode()
'
'Sheets("Summary"). Select
If Range("a7") = "complete" Then
'
Sheets(Array("1", "0")).Select
Sheets(ArrSh(1)).Activate
[Code] ......
View 2 Replies
View Related
Sep 24, 2009
How do I loop a select case so that it ends at a specific cell.
View 14 Replies
View Related
Jun 21, 2012
Below is the loop. An error occurs at Rows("y:y").Select
The y value that would be found in cell C500 would always match the row that would be selected and deleted. For example if cell C500 had the value 13, I would want Rows("13:13").select and then deleted.
Sub Macro2()
'
' Macro2 Macro
'
'
For y = 1 To 100
[code]......
View 5 Replies
View Related
Aug 9, 2013
I have a subroutine involving a Select Case and a loop.
I am of the opinion that writing the loop within the Select Case would be faster than having the Select Case within the loop.
Am I correct or does it not make a difference?
View 3 Replies
View Related
Sep 18, 2013
I am trying to loop through and read values from 4 combo boxes which I have renamed SaveOptionBox1 to 4. They are ActiveX controls. The code throws no errors but I can't output the values of my array 'dirname' on the sheet to prove it worked.
Code:
Sub Directory()
Dim ROOT_PATH As String
Dim cnt, dirnumber As Integer
[Code]....
View 3 Replies
View Related
Nov 18, 2011
My issue is I want to use a for loop to go through a spreadsheet. Within the for loop if a certain condition is true I want it to select all columns from A to AW and merge them together.
Example of what I have so far:
Sub MergeHeaders
dim i as Intger, LastRow as Integer
LastRow = Cells(Rows.Count, "CP").End(xlUp).Row
For i = 1 to LastRow
'Check if the leading character is a letter, not number
If Asc(Cells(i, "AP")) > 64 Then
'I want select from A to AW only for current row i, then merge
end If
next i
end sub
View 1 Replies
View Related
Jun 10, 2007
I am learning about Case Select-
I want to loop through every cell in col. V the range of
i = 6 to LRow
and find any value that equals 13, if it equals 13 then the value in (i,"W") will be "True"
View 9 Replies
View Related
Mar 20, 2014
How do I select the empty cell (once located after using the below loop) so I can paste into it?
[Code] .......
View 10 Replies
View Related
Feb 6, 2014
I'm looking to create a macro that does the following:
- Loops through a folder structure
- Opens a specific subfolder within each folder based on name (i.e. "*Financials*")
- Opens a specific file within that subfolder "*Financials*" based on both most recently modified a naming criteria (i.e. "*Model*")
- Performs an action on that file (a macro created elsewhere that I assume I can call here)
- Closes that file, and moves on to the next file matching the criteria above
As a self-diagnosed VBA novice, I'm having trouble adapting code found in various forums for my specific project.
I've found examples that address aspects of my desired macro or do similar things, but I can't figure out how to put them together.
Open most recent file:
[Code] .....
Loop through folders and subfolders and print all files:
[Code] ....
View 1 Replies
View Related
Jan 30, 2008
I've never worked with Excel macros prior to today. I'm working on this for a friend.
I've got this sheet that's going to a web address, importing a table from the page, and making a line graph of the data. I got all that to work fine (after a lot of trial and error). Now I've got the data, and I want to make a scatter plot of it...
Here's the thing. I want each month of the data represented as a line on the plot.
This is hard to explain. It looks like this:
[url]
So from there, I want a loop to scroll through the dates and select a range that represents January, a range that represents February, etc, so I can save those ranges as variables and make a scatter plot with 12 curves on it.
Here is the code I have so far, in case you want to see it, not sure why you might need to though.
View 14 Replies
View Related
Apr 9, 2014
I have developed a user form in VBA which is used for entry into an excel worksheet. From this data, I need to do the following:
1) Create 2 output files for Job data entitled "J" and another file entitled "S". The "J" and "S" is captured in a field in the data. I need to hit a button that allows these 2 output files to be produced, so I need to 'loop' through rows of the data to do this/
2) In addition to 1), the user needs to be able to 'select' the date range they would like to see 'J' and 'S' data over. This will be based on a field called "Startdate'. How could I do this with the button above-can I parse an input value to a form and select the 'J' and 'S' files on this.
View 1 Replies
View Related
Aug 2, 2012
How do I tell a loop command to stop after a certain number of sheets? The code below works for what I want to do but it saves all the sheets in my workbook bar the first one. I just want to save sheets 2, 3 & 4
Code:
Option Explicit
Sub mysaver()
Application.Calculation = xlManual
Dim counter As Integer
counter = 2
' counter is for the number of sheets in the workbook
Do While counter
View 1 Replies
View Related
Apr 5, 2007
I think I need a For Each Loop, but I'm not sure. I want to collapse all grouping to the highest level for certain sheets in a book.
Sheets("sheet1").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1
Sheets("sheet2").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1
Sheets("sheet3").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1
How can I specify which sheets to do this for and then loop thru all sheets to do it?
View 9 Replies
View Related
Mar 14, 2008
I want to perform an action on all but one of my worksheets. I've heard the array function can be used for this but I'm unfamiliar with its use.
View 9 Replies
View Related
Apr 24, 2007
why this code does not work on all the sheets in the active workbook? Actually it just work on the current active worksheet.
Dim ws As Worksheet
ThisWorkbook.Activate
For Each ws In AtiveWorkbook
ws.Activate
code here
Next ws
View 4 Replies
View Related
Oct 28, 2008
the code for looping through ALL the sheets in a workbook, copying ALL the cells and pasting the values?
View 5 Replies
View Related
Jan 28, 2009
I have a small macro that searches the sheets in a workbook and sends the info (if qualifies) to a new workbook before saving that workbook using a name date time format for records.
I woud like this macro to be able to repeat action in 8 more selected workbooks in a folder.
Question - can I name the workbooks I want to search - and - can I search all 9 workbooks before the data sheet saves and names itself, limiting access.
View 13 Replies
View Related
Nov 19, 2011
I have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?
Sub DelRow()
With ActiveSheet
.AutoFilterMode = False
With Range("m1", Range("m" & Rows.Count).End(xlUp))
.AutoFilter 1, "false"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
View 2 Replies
View Related
Feb 27, 2013
Is it possible that a VBA code could loop through some sheets in a workbook and save each one as an individual CSV file. The CSV filename would be the same as the sheet name.
View 2 Replies
View Related
Apr 5, 2007
I am trying get a set of code to run through the sheets in the workbook... All sheets EXCEPT 1 named "Summary".
How can I code the proper statement? This is my current
Private Sub cmdAddDistribution_Click()
Dim ws As Worksheet
Dim lCount As Long
Dim rFoundCell As Range
'check for selected cash flow
If Trim(Me.cboxCashFlow.Value) = "" Then
Me.cboxCashFlow.SetFocus
MsgBox "Please select a Cash Flow."
Exit Sub
End If...............
View 9 Replies
View Related
Nov 28, 2006
I am trying to loop all columns in each of a number of sheets using current region.
It selects the current region OK but the column counter only shows 1 as the number of columns in any sheet.
The Cells(6,1) likely has something to do with it but I do not know any other way to point to the current region I need. I do not know in advance how many rows or columns I am starting with but each has the required Row 6.
For x = 1 To Sheets.Count
Sheets(x).Activate
Cells(6, 1).CurrentRegion.Select
Selection.CurrentRegion.Name = "Mydata"
'Loop all columns in sheet
For y = 1 To Range("MyData").End(xlToRight).Column
Cells(5, y).Select
Next y
Next x
View 6 Replies
View Related
Jun 18, 2008
I have a WorkBook with many Sheets "imagine Sheets.count=50"
9 of the CodeNames for this Workbook's sheets are: sht01. sht02, sht03, sht04, sht05, sht06...
If I want to change the name "not the CodeName" of say "sht01" I can use:
sht01.name="New Name"
but is there a way of doing this whitin a For Next this way:
For X = 1 To 9
Sheets("sht" & X.CodeName) = X ' the Name X is just for this eg
Next X
View 9 Replies
View Related
Apr 23, 2014
I have a workbook with 180 Sheest. I need to copy sheet name and paste to column Name. In the Column Year write 2013.Finally I need to all sheets as show below in in Sheet Farms. Doing this one by one is time consuming and with error risk. I think a loop can do this,nevertheless, I don't Know how to do it. Column size can be different in each Sheet
Sheet name Famr1
CodNameYearDescTotal1Total2ProvCnt
1234Apples200xxxyyyzzz
3412Bananas400xxxyyyzzz
2358Oranges500xxxyyyzzz
8956Pines800xxxyyyzzz
[Code]....
View 6 Replies
View Related
Aug 21, 2014
How do I build a "For specific worksheets" loop?
I have a macro that works for a single sheet but I want it to loop over several. Currently, my code looks like this:
[Code] ....
View 6 Replies
View Related
Dec 21, 2009
However it will only add data to the active sheet when i am asking it to loop through the workbook missing out specified sheets. Would anyone be able to look over the code to see where the error is as to why it will not loop through the remaining sheets in the work book.
View 5 Replies
View Related
May 29, 2008
I am trying to loop a procedure that changes a cell value on 2 sheets in a workbook. I recorded a macro on one workbook and it worked fine. I then tried to modify the macro to loop this on more workbooks that have identical worksheet names. The macro is in a workbook named LIST, which column A has a list of all the workbook names. Currently there are 55 workbooks, but in the future I am sure there will be a few more. Here is a copy of the macro:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/28/2008 by MT
'
Dim STATEstr As String
Dim a As Long
a = Range("C1")
For STATEstr = A1 To A55
Workbooks.Open Filename:="C:ALLSTATES" & STATEstr & ".XLS"
Sheets("3 ANL").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = a
Sheets("3 ANLV").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = a
ActiveWorkbook.Save
ActiveWindow.Close
Next STATEstr
End Sub
The first error I got was a TYPE MISMATCH on 'For STATEstr = A1 To A55'.
There may be more things wrong with this looping. The only experience I have with macros is recording them and then modifying and combining them.
View 9 Replies
View Related
Apr 11, 2002
Input Workseet:
Col A: Date
Col B through M: Headings are employee names, data is how many hours of vacation per DATE.
User will enter a date in column A, and then the corresponding number of vacation hours a person took that day. There are a dozen or so employees, so we're only entering a record on the dates that someone has taken vacation time. Dates are mm/dd/yyyy format. The hours are number/two decimals.
What I would like:
An update command button (hey, I can actually do that part!) that has an on-click that:
Loops through each column B through M, and copies the information to the employee's individual sheet.
The individual sheets:
Columns are:
A = Date of vacation
B through M are months Jan through Dec.
Data starts *paste* in cell A12, where the date of the first vacation day they take should appear. If it was a half-day in February, .5 (or .50) will appear in cell A14.
If it's not clear, I'm happy to send the file! If you put your email here, I'll send it right away. If you email me at home, it'll be a few hours before I can send.
No rush on my part.
Really appreciate it!! I'm not a coder. I know small bits and pieces. When you start talking about Dim, I think of chinese food.
_________________
TheWordExpert
[ This Message was edited by: Dreamboat on 2002-04-11 10:20 ]
View 9 Replies
View Related