I have an worksheet that I import a csv into, each day a new csv is added to the bottom of the previous csv data. I have some code that extracts the date and month # from the cell and places them in helper columns. The code find the last used cell in the helper column and the imported data column to find the first and last row of the new day.
This part works fine. However, I assigned a variable name to the first and last variables and would like to uses these row number to define a range in order to use the range for a vlookup or find operation. This is where I get stuck. I want to use column x and row (variable from first bit of code) to column y and row (variable from first bit of code). Then use a vlookup/find whatever works to find the text I need and get the data. Tips on looping the code would be welcome as well.
I have searched for answers to the problem, on the board and web, but have not found a solution that works for me. (at least that I could get to work!!)
Below is the code as I have it
Public Sub Enter_Date()
Dim DateA As Date Dim DateB As Date Dim Cnt As Integer Dim End_of, Beg_of As Integer Dim Count As Integer Dim NumtoFill As Integer
Ultimate goal is to automatically update the source data for 4 pivot tables that are on 1 worksheet. The data for those 4 pivot tables are on 4 different worksheets w/in the same workbook. Consolidating into one dataset is not an option.
I'm familiar with a dynamic named range, but the 4 worksheets that contain the data are replaced daily via automated Access output which creates an error.
I know how to do this adhoc by matching the pivot table names with their respective worksheets, but there are many other documents with similar layouts where this would beneficial.
Below is an example of how I currently update 3 pivots on separate worksheets w/ the same data range which is w/in the same workbook. My proposed changes are below the current. Any ideas on how to return the workbook name as a string...Or am I going about this the completely wrong way...
I got this code I have been trying to solve but it does not work... What I need to do is define a worksheet and a range of that worksheet. I can only seam to work out either a worksheet or a range but not the two together.
Private Sub cmd_Cform_Click() Dim rng As Range Set rng = Range("A1") With Sheets("Customer") rng = .Range("A1") Application.CommandBars.FindControl(ID:=860).Execute End With End Sub
In general defining Sheet Level Name Ranges works fine with me, most of the times I use something like shown in the code below.
However, I have discovered that apparently the successfull execution depends on the sheet-name format itself
The code below works perfectly fine with worksheet names like "234", "cas422", etc but it fails to work with worksheet names like: "C12c", "eh34h4". It seems to me - but I am not sure of being able to generalize this - as if it works when the name contains [numbers][letters] or [letter][numbers], but it fails when it contains a mixture of both like [numbers][letters][numbers] or [letters][numbers][letters] .... in case of a failure of the code, I go into debug mode and simply rename the sheet, then everything's fine again.
Am I the only one to experience such difficulties? (I run Excel 2003 with SP3 on Windows XP) Or would a different code prevent this kind of trouble?
I think, I could write a workround, but before doing so I'd rather like to ask if I am doing something wrong here?
I'm trying to define a range to be copied during execution of a macro. The range to be copied must include all contiguous data from a defined starting range to the rightmost column and the bottommost row containing data (boht of which can change depending on input data). I use <End>+<RightArrow> and <End>+DownArrow> to define the range when working in Excel (not under macro control).
I used the macro recorder to define the code for the process described above, with results shown below:
Sub Macro2() Sheets("Source_Info").Select Range("A2:D6").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Copy Sheets("Working_Data").Select Range("A2").Select ActiveSheet.Paste End Sub
When I run the macro, however, the End(xlToRight) and End(xlDown) commands do not have any effect (i.e., the rang is not made any bigger when these statements are executed).
I've used the same code in previous macros (with previous versions of Excel and Windows), and it worked fine. I'm running Excel 2003 under Windows XP Professional now.
and the cell name have define to ="rawData!R7C3:R7C7" which the "" stop the rename working I belive.? What I want is to add or reduce extra column into the name depends on macro.
1. I need to define a variable range of all the USED cells in a column (starting at row 2 as the row 1 is the header)
2. I need to do this for columns A through to P inclusively (all using the same lastrow reference as that of column A)
3. I need to call the range name by the contents of the header in that column (Row 1)
4. Some of the data in the header row (row 1) contains spaces - can we change this to an underscore for the range name only?
5. Does a range only work for the active worksheet? Because i will have multiple worksheets, all with the exact same information in row 1, but different numbers of rows (and different data as well), but i will need the range defined on each worksheet......
I've found the following code and thought it was it, but it only defines on 1 worksheet, and for some reason only defines ranges for columns 1 and 2. Also it defines the range as A1:A65535 - not the USED range.....
I'm trying to create a user defined function to drop into dblookup functions that will always reference the first cell in an associated column and the first cell in the row of an associated column.
I came up with the following, however the problem is that the udf always returns the values for the active cell's, row and columns.
Function SRCref2() Application.Volatile
myfield1 = ActiveCell.Column Dim1 = Columns(myfield1).Range("a1").Value SRCref2 = Dim1 End Function
I would nest these in a formula such as "=srcsum(srcref2(), srcref3())". Ideally I could then use this same funtion anywhere instead of having to use and worry about the accuracy of "=srcsum($a$2,$b$1)"."=srcsum($a$3,$b$1)"."=srcsum($a$4,$b$5)".etc.
It seems like there should be a current cell method or something but I can't find it and I'm not smart enough it seems to use vb to designate some kind of floating intersect as a base for a row and column reference.
I am trying wihout suceess to create a range to copy in a macro each time the macro loops. This is thus a dynamic range. My failed attempt is listed below. How is this done?
ColumnAdjust=2 For I = 1 To 282 Range ("B5").Select Range(ActiveCellOffset(0,ColumnAdjust),ActiveCellOffset (0,ColumnAdjust+1)) Range(Selection, Selection.End(xlDown)).Select Selection.Copy . . . ColumnAdjust= ColumnAdjust=2 Next I
I am attempting to create a dynamic range within a macro.
Each week, a list of performance factors is recorded for employees. The macro is about to do an Advanced Filter to create reports based on user-provided criteria. Since there is new data every week, the range used for the Advanced Filter is dynamic. The code for the Advanced Filter refers to a range entitled “Database.” My problem is in defining “Database.”
It is currently 534 rows and 8 columns, starting at A1.
The relevant portion of the macro currently reads:
When running the macro, the debugger stops at the line which starts "ActiveWorkbook.Names" and tells me “Run-time error ‘1004’. The formula you typed contains an error.”
The "Sum" sheet can change its number of rows. The pivot table is based on it. I'm having trouble with the SourceData portion of the code in my macro ....
I have a Ranking tab that has the persons name, weeks, months that subtotal into 2 columns, MTD and YTD. I have set up with 2 Macros to sort based on two columns based on their selection of MTD or YTD.
What I did not take into consideration is if a person was added at the bottom of the list.
Is there a way to modify this to include rows that may be added?
I am still having some difficulty in getting a macro to select a print range on a text file imported into excel. All the data pulls into column A which is OK. I'm trying to get my macro to highlight & select the print range by going Home, End Down, Tab right Tab right and then select whatever that highlighted range is. This range will change from file to file.
My macro reads as follows:
Sub PrintToView() ' ' PrintToView Macro ' Macro recorded 5/5/2004 by ' ' Range("A1").Select
I am looking to run a marco for a selection range, and the selection range could vary in size. Using the Macro recorded (whilst turning on the relative reference) the Macro runs for a defined number of cells. I would like to run certain Macro, for different ranges of cells.
I am not sure if my problem is in the dynamic range or not. I have attached a small sample file. I tried to create a dynamic range by creating a named range of my "LabelRow" with the following as the refers to: =OFFSET($C$32,0,1,0, COUNTA($32:$32))
When I set my cursor on this, Excel makes an outline on the whole row 32 where there is data, which gives me some clue that it understands what I am trying to define. Next, I try to pick this range up and paste it using named ranges in a macro (CopyRange). It gives me an error like it doesn't understand the named range. I do similar macro code in many other places in this project and it works with non-dynamic ranges. Here are some other details on this project. I need a dynamic range because I insert new data into the dataset, which may be 2 quarters up to 20 quarters. This insert causes a regular range to be messed up. My ultimate goal is to graph selected rows of data with the same labels, but I need to have it starting at Q1, which is pushed to the right as new rows are added.
I am trying to select rows in excel using a macro and then hide the rows, but i want to be able to add rows within this selection and still be able to hide the complete selection of rows.
The macro i am currently using is shown below: This hides rows 131 - 205, but if i was to add in another row in between so the range i now want to hide is 131-206 can i get the macro to update to this new range?
I want to define a Range() in VBA. have cell1 and Cell2 in the format of rows and cols. ie. Cell1 = Row 1, Col 2. Cell2 is dynamic, can be sometimes row100, Col200, or Row23, Col 1000. May i know how to define it in VBA?
I have two columns containg the arrival and departure hours of workers. From these columns I must define the workshift by specifiyng the time range for each shift. AZ contain the arrival hours while BA the departure.
The formula I use doesn't return the results correctly because some shifts are almost the same. i.e: if shift one starts (arrival hours) between 05:00 and ends at 12:59 and shift 1-2 starts at 08:00 and ends at 23:59 then it will go with the first shift even though the times in range belong second shift.
Dim DRange As String Dim ERange As String Dim SRange As String EndRow = Range("A65536").End(xlUp).Row DRange = Range("D1", "Z" & EndRow) ERange = Range("E1", "Z" & EndRow) SRange = DRange
how to define the end of a range using a variable determined by a rng.Rows.Count command (or anything else)? Is this even possible? Here is what I currently have:
Set rng = Range("A1:A10000") For i = rng.Rows.Count To 1 Step -1 If rng.Cells(i).Value = "0" Then rng.Cells(i).EntireRow.Delete Next
I'd like to define the end of the range with more accuracy than I'm currently doing.
I am searching for data, upwards from cell A1400. Once I find data (cell > 0), I need to count up 27 rows and then select these rows for columns A to E. Then I want to copy this block of data and paste it. I have been having difficulty with the selection of a block of data which will be in a different position depending upon the data used. The code I am using is below. The two lines that I need to replace with a Variables cell range reference are:
Sub CalculateATR() Sheets("Data").Range("a1400").Select Do If ActiveCell.Value > 0 Then ActiveCell.Select Exit Do Else ActiveCell.Offset(-1, 0).Select End If Loop Until ActiveCell.Value > 0
Range("A1268:E1242").Select Range("A1268:E1242").Activate Selection.Copy Range("G5:K31").Select ActiveSheet.Paste Else End If End Sub