Define A Time Range
Jan 21, 2010
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.
View 8 Replies
ADVERTISEMENT
Jan 23, 2007
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?
View 2 Replies
View Related
Feb 23, 2013
why this won't work.
Code:
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
View 6 Replies
View Related
May 19, 2008
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.
View 9 Replies
View Related
Apr 25, 2006
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.
View 5 Replies
View Related
Aug 13, 2006
is it possible to creaate a macro to highlight a range that starts at a1 to a? and there could be blanks amongst that range. the range will be unknown
View 9 Replies
View Related
Dec 22, 2006
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:
Range("A1268:E1242").Select
Range("A1268:E1242").Activate
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
View 8 Replies
View Related
Feb 7, 2007
how to set up an array within a worksheet
View 3 Replies
View Related
Mar 26, 2008
how do you go about referencing a cell by using a value of an integer? For example, I want to select cell A5. I have the number i= 5 (in my vba code) and I want to use that together with the row letter A.
View 4 Replies
View Related
Feb 26, 2014
is there a simple way to do a vlookup (or any other more appropriate formula) using the value of another cell to define the named range relevant to that lookup.
eg I will have two different ranges for fitness performance levels, each of these will be named "Male" and "Female".
I would like to do a lookup based on a formula as follows: Try this formula. Column letter & Row number are for example only. Array formulas will have curly brackets {} emcompassing the ENTIRE formula. You do not add these, you Enter the formula with Ctrl+Shift+Enter and Excel will add them (details: Array formulas). Many more Excel Formulas Z100 =vlookup(D4,NAMED RANGE,2,false)
the Named range would be a value in the same row ie B4 - being Male or Female
so I am hoping for something like Try this formula. Column letter & Row number are for example only. Array formulas will have curly brackets {} emcompassing the ENTIRE formula. You do not add these, you Enter the formula with Ctrl+Shift+Enter and Excel will add them (details: Array formulas). Many more Excel Formulas Z100 =vlookup(D4,B4.Value,2,false)
otherwise I could just use an If and do something like: Try this formula. Column letter & Row number are for example only. Array formulas will have curly brackets {} emcompassing the ENTIRE formula. You do not add these, you Enter the formula with Ctrl+Shift+Enter and Excel will add them (details: Array formulas).
Many more Excel Formulas Z100 =if(B4="Male",vlookup(D4,Male,2,false),vlookup(D4,Female,2,false) )
View 2 Replies
View Related
Nov 27, 2013
I need to be able to work out a percentage based on a value range. ie.
Cell D2 to D5 will define the percentages (so I can adjust it and play)
D2 = 18%
D3 = 15%
D4 = 13%
D5 = 10%
I need to work out:
If the value in cell A10 is between 11 and 200 calculate on D2, if between 201 - 500 calculate on D3, if between 501 - 2000 calculate on D4 ect ect
Cells A10 to A100 will have some figures put in them.I then want to calculate the %value used based on weather the figure in one of the A10 to A100 cells falls in a range. The data being put into the cells in column A will vary from report to report.
I'm trying to automate the calculations :
View 6 Replies
View Related
Jul 19, 2014
I am working on some code to copy data from one sheet to another, but I'm not sure if I'm going about defining the copy range correctly. I would like it so that the user can highlight a range of cells on the sheet between A3 and F last row (last row based on col C). However the user should be able to highlight rows in any column between A and F, and they could highly the records with just one column or multiple columns. It should take the row numbers of the highlighted range and use the that as the row number to extract the data from.
[Code] ........
Im currently getting runtime error 13 on 'CopyRange = Selection.Rows'
'CopyRange = Selection.Row' returns the single row number for the first cell in the selection, but i need the range of all the rows in the selection.
View 6 Replies
View Related
Jan 27, 2009
How can I define a range, only for the active cell?
View 6 Replies
View Related
Jan 25, 2012
I have a daily collection of data based on half hour meter readings. Responsibility for this data is to be split between core and non-core hours so for example core hours would be from 6:00 to 18:30.
What i would like to do is have a combobox for both the start time and end time allowing the user to change these as appropriate.
Where i'm struggling is using these comboboxes to select the data between these two times and total the values per row.
My data is currently arranged with the times (staring at 00:00) running horizontally on row 14.
View 9 Replies
View Related
Feb 14, 2013
The way I have try to define lastcell is wrong. But I don't know how to do it.
Code:
Sub createUniqueRecordID_2()
'
' fill using CTRL + ENTER
'
Dim lastcell
Sheets("projects list").Select
[a1].Select
[Code]...
View 1 Replies
View Related
Apr 30, 2013
I found some code online that works great for defining a named range. My only issue is that occasionally my worksheet name will contain spaces. this throw off the current code. i do know that if i manually go in to the range and add a "'" to the beginning and to the end of the worksheet name it fixes it. unfortunatly i cannot figure out how to add the "'" in the following VBA.
Code:
Sub AddDynamicRangeVertical()
On Error Resume Next
Dim sRangeName As String
Dim n As Name
If ActiveWorkbook Is Nothing Then Exit Sub
[Code] ..........
View 4 Replies
View Related
May 12, 2014
I can't quite get this formula to give me the correct value.
imgur: the simple image sharer
I tried defining as a Range and I can't get it to work right either way. When I hover over my r1 and r2 values the range is correct but it does have "$A$227:$A$447" quotes around the range so I think that is messing me up.
View 4 Replies
View Related
Nov 3, 2008
I'm trying to define a dynamic column range call 'Cost'
If it starts in Column C, row 4 [C4]. I want the range that to go down to the Row I have defined as 'subtotal'
The user will be able to insert new rows above 'subtotal'
How can I define Column C4 so that any new row added will be including in the defined row range 'Cost'?
View 9 Replies
View Related
Nov 8, 2008
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
View 9 Replies
View Related
Dec 29, 2009
I am trying to define a number of ranges in different sheets using VBA I am using the follwoing syntax but I am getting a 1004 error:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ThisWorkbook.names.Add Name:="Test", RefersTo:=Worksheets("Sheet1").Range("E6", Range("E6").End(xlDown))
End Sub
As long as I have sheet1 active, it works. If I have another sheet active and change smt, i get the error.
The code is located in the ThisWorkbook object.
View 6 Replies
View Related
Jul 22, 2006
How can I take the source data of a chart to be all those cells in the column, that begin with the number "1"?
View 2 Replies
View Related
Nov 21, 2006
How can I redefine name of the cell? This is what I have tried and not work
intWDColumn = Range("rngWaterDepthStart").Column + 3
intWDColumn = intWDColumn + 1
strNameRange = "rawData!R7C3:R7C" & intWDColumn
ActiveWorkbook.Names.Add Name:="rngWaterDepthStart", RefersToR1C1:=strNameRange
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.
View 4 Replies
View Related
Nov 22, 2006
I want to define the range from a given cell and all data below within the same column strDataStart is the named cell in the worksheet that want to start from. Below is what I tried and failed.
Function rngDataCol(strDataStart As String) As Range
Dim rngDataEnd As Range
rngDataEnd = Range("strDataStart").End(xlDown)
rngDataCol = Range(Range("strDataStart").Address, rngDataEnd.Address)
End Function
View 5 Replies
View Related
Dec 26, 2006
I am trying to create a correlation matrix that uses the =ADDRESS function to define the various columns of data which I want to correlate against each other (I require this flexibility because the number of columns and rows of data to be correlated will change). The basic formula I am using is something like the following: =CORREL((ADDRESS(Sheet1!$C$2+3,L2+2,,,"Sheet1")),(ADDRESS(Sheet1!$B$2,L2+2,,,"Sheet1")))
However, while the individual ADDRESS fomulas deliver the correct start and end cell references required, it seems that CORREL function won't accept the cell addresses that result from using the =ADDRESS function.
View 5 Replies
View Related
Apr 4, 2007
I'm having trouble assigning a range of a single cell using vba. I'm doing this to create charts. Here's the sub containing the problem
Private Sub AddNewSeries(Target As CTarget)
Dim i As Integer
Dim Match As Boolean
Dim rValid, rInvalid As Range
i = 2
Match = False
Do While Match = False
If Sheets("Graph Data").Cells(1, i) = ReportTargetBox.value Then
Match = True
MsgBox ("report name match")
Exit Do
Else: i = i + 1
End If
Loop.....................
This msg box :MsgBox ("Cell Value = " & Sheets("Graph Data").Cells(2, i).value) is working and returning the correct value.
View 2 Replies
View Related
Feb 18, 2008
I am trying to figure out how to copy a variable range of data from one worksheet to a new one. I have the worksheet part of it figured, but not the range part. How do I define a range to include both columns and rows in VBA?
View 4 Replies
View Related
Aug 5, 2008
I am building a macro to conditionally edit cells that meet certain criteria within the current selection:
Dim FinalStr As String
If CheckBox3.Value = True Then
For Each cell In Selection
If cell.Font.ColorIndex = Range2.Font.ColorIndex Then
FinalStr = FinalStr & "," & StrConv(cell.Address, 1)
End If
Next
End If
FinalStr = Right(FinalStr, Len(FinalStr) - 1) 'To remove extra "," at the beginning
What I am getting from this macro is a string like "$I$27,$J$27,$E$28,$F$28" that I use later to edit that range, for instance
Range("$I$27,$J$27,$E$28,$F$28").ClearContents
It worked fine, however, I found later that XL cannot handle more than 20-30 individual cell addresses. The error msg I am getting is: " Method 'Range' of object '_Global' failed " Note that it won't be very practical to pick the cells and edit them within the same loop since there are several criteria times several edit options.
View 9 Replies
View Related
Jul 21, 2009
I have a range staring with cell "A5" and going to Column "K8+" that I need to copy. My issue is that the number of rows to copy will change. I have the number stored a variable "a" in my coding. how do I code this to work?
View 5 Replies
View Related
Dec 21, 2013
I have a daily data dump that starts at the beginning of 2012 up to the current date. I have an executive view that allows the user to see metrics(in a data graph) from the current date back to a date selected from a drop down menu. I would like to have it so they can choose what the end date will be as well as the start date. I have tired using offset with very little luck. Is there a way I can accomplish this task with VBA? Everyday a new row of data (for the previous date) is added to the front sheet. So row 1 is a header row and then row 2 is 01/01/2012, row three 01/02/2013, etc.
View 7 Replies
View Related
Nov 13, 2006
I'm fairly new to VBA and I need to define a variable as a date range
i.e. Period1 = 1Apr2006 to 29Apr2006, Period2= 30Apr2006 to 27May2006 etc
View 9 Replies
View Related