Selecting Range Variable In Different Worksheets Within Same Workbook
Aug 22, 2014
I want to make a range variable ("testrange") that I can use to define a range of non-continuous cells and then use that range variable to select that range of cells in different worksheets within the same workbook.
I tried the below code (simply coloring cells red), but get an error when I try to select "testrange" after moving to the next worksheet.
[Code] .....
The next worksheet is also supposed to have the same range of cells colored red, but I can only get it to work on the first active sheet.
I would like to avoid having to repeatedly rebuild the range I want selected each time I move to a different worksheet.
View 7 Replies
ADVERTISEMENT
Apr 2, 2014
Basically, i have a common workbook template that is used by multiple users across the business to request a cost for numerous new products.
Within the template, there is a common section at the top, where specific project information is entered. There is also a table beneath where 1 or many products can be entered, with specific information relating to that product in the same row.
All the submitted requests are uploaded via an email attachment, to a particular sharepoint directory.
What i would like to do in the master workbook is the following:-
1. Open in turn every uploaded workbook within the sharepoint directory and copy the following cells into the master workbook, each in it's own row (or next available), with the data in adjacent cells.... 1st cell to enter data is $B6.
Cells to copy from each sheet:
Common info contained within cells:
$DG$2,$N$11,$N$12,$N$19,$N$13,$AO$7,$AO$8,$AO$9,$AO$10,$AO$11,$AO$12,$AO$12,$AO$13,$AO$14,$BO$8,$BO$11,$BO$14
Product specific info: $U37, $AD37, $AH37, $DH37, $C37, $O37
Depending on the number of products requested, we need to repeat (loop?) until it finds the next blank row in the table. I have hidden a blank row in the table, so there will always be one!
All of the common information needs to be included for each product specific entry.
For each file, once the upload has been completed, i would like the file to be moved to another "archive" directory.
I have attached the template for information. The master workbook is still in development so can't share currently.
View 12 Replies
View Related
Mar 19, 2012
I have below code which I was thinking is very simple to select variable worksheets. However I get Debug error when running:
Code:
Dim rng As Range
Dim cl
Set rng = Sheets("Budgetted sku's").Range("A2:A24")
For Each cl In rng
Sheets(cl.Value).Select
Next cl
View 5 Replies
View Related
Apr 4, 2013
I want to copy a range where the row is variable (i in the Loop I'm doing) but the columns stay the same. What am I doing wrong?
Workbooks("Labor Info").Sheets("Transfer").Range("A" & i & ":E" & i).Select
View 1 Replies
View Related
Feb 26, 2009
I need to select starting with:.
Columns A-O
Rows 1 - ( LR of ColB - Col A is empty )
View 9 Replies
View Related
Aug 28, 2009
I require vba code which will allow me to select a range of variable size.
Starting from cell A2 use :
Range(Selection, Selection.End(xlDown)).Select
However then using the line below may not select the entire range as some columns may be empty
Range(Selection, Selection.End(xlToRight)).Select
View 9 Replies
View Related
Jun 3, 2006
I am trying to enter code into a Macro that will select a range and then put a subtotal at the bottom of the range.
I have values in col D & E that I am multiplying together in column F. I then want the macro to select a range from F2 to the last Value in col F and then put a total in the next cell down (in col F). The range needs to be variable.
View 3 Replies
View Related
Jun 21, 2006
I have a workbook that generates sheets for each year based on selected criteria. It starts at Column H and goes too AH and beyond. When my loop reaches Z it errors out. I think this is happening because the code is referencing the column as ASCII. Here is the
Sub Test()
Dim d As Date
Dim yrint, i, num_years, fields, field_start As Integer
Dim yrstr, crit1, crit2, left_column_range_fixed, right_column_range_fixed, left_column_range_var, right_column_range_var, left_column_range, right_column_range, cost_column, cost_column_var, cost_column_fixed As String
left_column_range_fixed = "H"
right_column_range_fixed = ":AH"
cost_column_fixed = "2"
crit1 = "=x"
crit2 = ">0"
d = Date
yrint = Sheets("Overall"). Range("H2")
field_start = 9 'changed from 9....................
View 4 Replies
View Related
Jan 20, 2012
I've got some code which some one posted me a link to on here which set up a pivot table on more that 1 sheets (using excel 2002).
I inserted this code into a rountine I do daily which works fine.
The problem Im having is that Im getting more and more info which I need to pivot over more than one sheet. So I was going to amend the rountine so It picked what ever sheets are in the work book to pivot.
At the moment I have to go into the code and name the sheets to pivot. Is there some code which can work out how many sheets that need pivoting and just do it with out naming them? and also just add a new sheet with the pivot on rather than having to name the destination?
I've posted the code i got given below and have highlighted the bit where I have to name the sheets.
Code:
'---------------------------------------------------------------------------------------
' Procedure : CreateConnection
' Author : KL (Kirill Lapin)
' Date : 18/08/2009
[Code]....
View 8 Replies
View Related
Apr 26, 2006
How do I modify this macro so that the worksheet array will select all the worksheets except sheet 1?? My workbooks will have varying numbers of worksheets ...
View 3 Replies
View Related
Feb 12, 2010
I have a closed workbook with data in 12 columns. I have an other workbook where I choose a column and the formula needs to return the sum of the data from column 1 to the chosen column, in a given row. I can't use INDIRECT or SUMIF because of the closed workbook, so I'll probably need a formula using sumproduct, but I can't find a solution on the net.
View 2 Replies
View Related
Apr 3, 2009
I've successfully copied the array of equations using the VBA that Pjoaquin enlightened me with from my last thread. The outcome was Sheet2!A2:O2 being successfully populated with the equations from my first sheet... but here comes the problem: I'm looking to autofill A2:O2 down to the last record in Column P. But the number of records in this table is varable.
View 2 Replies
View Related
Feb 18, 2012
I'm trying to make a macro'd button that when clicked will select the cells A1:A?? where ?? is equal to the value in cell B1
B1 is a variable number that changes to be the proper amount of rows that I require selected.
It's always A1 down to A9 minimum and A1 down to A400 max.
Once selected I need the macro to copy the selected cells to the clipboard for another application to be able to paste that info.
So far I've been able to get the copy command to work and the range command to work but can't seem to figure out how to put the variable number from B1 into the range command.
View 3 Replies
View Related
Oct 2, 2013
I've made a macro and spend some time making it work across different sizes of data. The last issue I'm having is after the macro sorted out some data, that it will then delete, it has to select the first row and shift select down before deleting it. However, depending on how the data is sorted, the first row could be 9, could be 10 and so on. See below for my code.
Code:
Sub Macro1()
Windows("statistik.xls").Activate
Range("A8").Select
[Code]....
If the first row in my data set is not one of the 3 criteria ("Personligt ejede virksomheder", "Privat", "Reklamebeskyttet"), then the first row # will be 10 instead of 9. If the first two rows are not one of the 3 criteria, then it would be row 11 and so forth. How do I make my macro take this into consideration?
View 4 Replies
View Related
Jul 16, 2007
I am currently working on a simple macro to help with formatting a spreadsheet. The number of tabs on the spreadsheet will change to reflect the number of companies I'm running reports for. But the same process is to be applied to each tab. The issue I'm facing is I don't know the appropriate code to select all tabs without specifically referencing them.
The code that I would like to apply to all tabs is as follows:
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$85"
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
View 9 Replies
View Related
Mar 14, 2012
The code im using all worksheets. How do I make this sort all but the first
For Each WS In ActiveWorkbook.Worksheets
If WS.Name "Sheet1" Then
Range("A1:X2270").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
View 1 Replies
View Related
Mar 21, 2008
I recorded the following macro to select all the worksheets in the Activeworkbook by clicking on the first worksheet and then hitting Shift Tab and selecting the final worksheet (thus '[Group] selecting' all worksheets in the active workbook).
Sub Macro1()
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
Range("A1:B2").Select
End Sub
How do you generalise the Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select if the number and names of worksheets varies from workbook to workbook?
View 9 Replies
View Related
Jul 12, 2012
I have a workbook with 3 worksheets which contains a single spreadsheet where the user enters data and 2 worksheets containing all the named ranges and formulas(divided up by product model) used on the data entry worksheet. What I've been trying to accomplish is to choose one worksheet based on which product model I select on the data sheet.
View 1 Replies
View Related
Apr 26, 2006
I have a workbook called MASTER. MASTER has a macro I need to run in another workbook(wb2) I receive thru email. The problem is that wb2 can have any given name because someone else creates it.
With MASTER and wb2 (which can have any name) open, I need a macro that would select and/or make active whichever other workbook is open OTHER THAN MASTER.
View 9 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
Jan 3, 2013
trying to import another excel workbook with its location being flexible as the file-name will change.
This is what i got so far
Code:
Dim selectFile As String
selectFile = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls*" _
, FilterIndex:=1, Title:="Open Excel file" _
, MultiSelect:=False)
[Code].....
View 9 Replies
View Related
Oct 2, 2008
To initialize some cells/ranges, I am copying a given range and pasting it to another given range using the. Copy and .PaseSpecial methods. However, it would seem that both methods actually select the range(s) for the operations, i.e. the given ranges(s) are activated/selected thus changing the focus on the spreadsheet. I would like to perform both operations without actually selecting the given ranges.
View 5 Replies
View Related
Apr 28, 2006
I am receiving a 'subscript out of range' error on the lines of code below.
I would note that all variables are declared and all seem meaningful as regards what you would expect at that point.
Below is a snippet from the immediate window which indicates what the values are:
completecashname C:CashDevelopmentMyFolderoutputCASH042706.xls
cashsheetname Formatted Sheet
cashcurrcolumn A
cashfirstrow 2
cashlastrow 876
Also the workbooks are both closed at this point (but it makes no difference)
Set CashCopy = Workbooks(CompleteCashName).Sheets(CashSheetName). _
Range(CashCurrColumn & Cashfirstrow & ":K" & Cashlastrow).Value
Set PelPaste = Workbooks(completepelname).Sheets(PELSheetName). _
Range((PELCurrColumn & PELlastrow)).Value
View 8 Replies
View Related
Nov 5, 2013
I am working with two files everyday: today's and yesterday's. Each report has the day's date in the name of the file.
So I'll take today's (11-5) and import it into yesterday's (11-4). Then, tomorrow I'll take 11-6 and import into 11-5. The day after, I'll take 11-7 and import into 11-6. So on and so forth. I'm trying to figure out how I can get VBA to accommodate these changes in names. So that it sees the date in the name of today's report, sees that it is today's, then selects yesterday's (or says "Open yesterday's report!"), and imports the information.
I can figure out everything else, just not the naming issue.
I guess I could always stipulate to the person running it that they should only have these two workbooks open and that they should run the macro starting in yesterday's workbook. Just writing VBA code to select the only other workbook so VLOOKUP can be done from it. But I am trying to make it fool proof.
View 1 Replies
View Related
Nov 10, 2006
Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?
I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.
View 5 Replies
View Related
Sep 13, 2013
I have x number of sheets in a workbook, and I am looking to copy sheets a, b and c into a new workbook that I will create.
The a, b and c are in no order, or consecutive (although they could be). I want to be able to count the number of sheets in the workbook, and traverse through that to find sheets that I need, and select them to copy over to a new workbook.
View 1 Replies
View Related
Jul 17, 2014
I have an employee schedule that is a whole year. I'm trying to extract only the next two weeks worth of columns. I'll schedule it to run once a day. Some information... The calender has the dates listed in Row 2 on Sheet called Daily Schedule The 2 week calendar would be on sheet 7 called Two Week Calendar There are only weekdays on sheet 1 Daily Schedule so if there is nothing matching today's date just stop and do nothing I would like it to save the whole file when complete
I have written some of the simplest code but I don't know how to select by today's date then copy that column plus 9 to the right.
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("C:Schedule.xlsx")
[Code]....
View 2 Replies
View Related
Dec 19, 2006
is there any way to open a workbook and select a sheet within the book without having the entire name?
I've got a unique workbook and worksheet identifier but don't know how to use wildcards to get my macro to open the right workbook.
View 9 Replies
View Related
Dec 13, 2008
I have a worksheet which is used by multiple users at the same time, at the end of the day I can have upto 10 files. The layout of all the files is the same, same number of columns and rows, the only difference would be the file name eg:Test1.xls, Test2.xls etc. information in test1.xls will not be any other file. At the end of the day, these files are emailed and saved in a particular folder.
What I need is get information from all the files saved in a particular folder and keep columns which have data. Additionally, if there is no data for any columns after combining the columns to display an alert. The final file should have information with only data in individual columns and arranged in the order such as Center 1, center 2, Center 3
Eg:test1
Column A Column B Column C.....upto 30 columns
Center 1 Center 2 center 3....upto 30 centers
1 4
2
3 5
test2.xls
Column A Column B Column C.....upto 30 columns
Center 1 Center 2 Center 3.....upto 30 centers
5
The final file will look like this
Finaltest.xls
Column A Column B Column C.....upto 30 columns
1 4 4
2 5
3 5
View 9 Replies
View Related
Apr 4, 2007
I have a main workbook that uses a macro to open a workbook provided to me from another department. This workbook contains a sheet that is basically a copy of the sheet in the main document and has the same sheetname and same codename.
The macro should copy the sheet data from the site workbook to the sheet in the main workbook. However, when i tell the workbook to select the sheet in the site file using its codename it errors....
View 6 Replies
View Related