Union Selection Without Looping Through Cells?
Apr 6, 2014
how one can union a selection without looping through the cells? I need to write a noncontinuous range into an array, and it can't be sorted as I'm using specialcells(xlCellTypeVisible).
View 1 Replies
ADVERTISEMENT
Jul 15, 2014
I'm trying to make a code so that when optionbutton1 is checked, it allows you to right click to select a cell, then right click on a different cell and select that cell as well as the previous cell, etc. Here's What I have so far.
[Code] .....
View 6 Replies
View Related
Nov 12, 2012
I'm trying to select the same cell and a blank cell multiple with a UNION(). Is this possible?
Here's a summary of my code:
Code:
Dim c
Dim Rng As Range
Dim blankC As Range
Set blankC = Range("XFD1048576")
Code] ......
Ultimately, I'm trying to copy various cells and reorganize them including blank cells to conveniently use UNION for a quick copy and paste as opposed to explicitly defining where to paste everything.
View 9 Replies
View Related
Aug 24, 2013
I would like to check if selected cells is a union of several ranges or one solid range. I am sure there is a way, but did not manage to find it. How to do it?
View 2 Replies
View Related
May 19, 2014
I am trying to create a union range that is comprised of two cells that are no where near each other on a worksheet. I keep getting the object required error. Everything else works perfectly.
Dim myRng As Range
Set myRng = Application.Union((Range("IndData1")), (Range("IndData2"))).Activate
Do Until ActiveCell = ""
Selection.Copy
[Code] .....
View 1 Replies
View Related
Mar 19, 2014
I have to manually drag my formula for 121 cells and then change the formula by next column and/or row number.
Currently the 2 formulas I have are:
=IF(AND($Z$4>="", $AA$4>=""),H$6,J2456)
=OFFSET(X$5,0,(ROWS($1:1)-1)*2)
After every 121 cells that I drag these formulas to, in the first formula I change from H$7 to H$7 then H$7 then H$7 and so on
In the second formula, I change from X$5 to X$6 then X$7 then X$8 and so on.And also change the ROWS from 1:121 back to 1:1
Is there a formula which I can drag and it automatically changes the column and cell reference in the 2 formulas?
View 6 Replies
View Related
Dec 20, 2006
this is in reply with my previous thread I started regarding counting cells depending on dates. I am trying to loop between cells A19:A40 and perform some actions inbetween on each step. So, cell A19, do some work, then move to A20, and so on until it gets to cell A40, then it stops. I cannot work out the VBA for it.
View 4 Replies
View Related
Apr 16, 2007
I need to compare cells in two worksheets but with a difference ex:
Worksheet 1 contains merged/single Cells
Worksheet 2 contains single Cells
Now , i fneed to compare first merged/single cell in Worksheet1 with first single cell in Worksheet2 and similarly , second merged/single cell in Worksheet1 will be compared with second single cell in Worksheet2 and so on.........
Though i can use exact and compare them maually by specifying cells but since i need to make it general , suppose second time there can be some other combination of Merged cells I need to compare with Worksheet2 .
View 9 Replies
View Related
Apr 8, 2014
I have a normally easy task that is causing me some grief. In column f of my data I either have a number or this "____________". My goal is to delete the entire row if that line is present but my code is not finding that value in my range.
I am wondering is this some format value or something, but it shows up in the formula line as a line. Doesn't appear to be an underline, but I could be wrong. Below is my code.
[Code] ........
View 9 Replies
View Related
Jun 29, 2014
I have code which copies Range("A1") and pastes into Range("c1").Then it loops to copy a2,a3,a4 and pastes in the same cell c1.
I just want to copy a1 and b1 instead of just a1 and paste into cell c1& c2.Then loop to copy a2&b2 till end.
[Code] ......
View 5 Replies
View Related
Feb 23, 2014
I have a range of cells in F2:F30000 that I want to round to the nearest whole number.
How can I do that to the entire range of cells without looping? Every search I perform on the topic has a loop of some kind as a solution and my data set could be over 100k rows and speed is already a concern with the workbook.
View 2 Replies
View Related
Mar 6, 2010
I've written a macro which searches the sheet for a value, when it finds the value it does something, then I want it to keep looping until it's done.
The issue is that Excel's find does not search first to last. Once it gets to the last, and you search next, it goes back to the beginning and finds the first cell.
In order to break out of the loop, I figured I should store the first cell found in a variable and then check inside my loop to see if I have got looped back to the beginning. If I got back to the first cell found, then I exit my loop and I'm done.
However, my code doesn't work. It exits the loop after a couple of iterations.
Sub Macro5()
'
' Macro2 Macro
'
If WorksheetFunction.CountIf(Cells, "TEST") = 0 Then
MsgBox ("Not Found")
Exit Sub
End If
Cells.Find(What:="TEST", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
.Activate...............
View 9 Replies
View Related
Feb 16, 2010
i m looping through each cell in the range A5:G11 and deleting the last part, "',[ABSMacro.xlsm]Region Breakdown'!$S$1:$S$64999" of the formula in each cell.
View 2 Replies
View Related
Oct 31, 2013
First, I have to say that I am very weak in VBA.
I have a section of code where I need to count the cells from J through BF in rows 42 through 76. The code snippet I'm working on is:
Code:
For r = 42 To 76 Step 1
if Application.WorksheetFunction.Count(Range("J" & r:"BP" & r)) = 0 Then
Err = Err + 1
[Code]....
The code checker highlights the ':' in the 'Range .... = 0' with the message "Expected: list separator or )".
View 2 Replies
View Related
Dec 29, 2008
Quick question: When using "With" is it possible to specify 2 ranges, or will I need to do 2 different with blocks? The reason I say not using Union is because I need my ranges seperate. I run 1 set of commands on Range 1, and 1 set of commands on both Range 1 and 2.
View 3 Replies
View Related
Apr 29, 2009
(Using Office 2003 on XP Pro) I have two named ranges that I want to union into one big named range so that I can use the big named range in a validation table. Unfortunately the big range does not appear on the list of named range so I switched to VBA to try and lick this but really I was hoping a non-VBA solution exists. Exploring possible VBA solutions, here is what I have so far:
View 6 Replies
View Related
Mar 3, 2008
I'm trying to union two different ranges that exist on two different sheets and then copy the unique values into a third range with just the unique values. I was going to then use the unique range as my rowsource in a listbox. This is the code I was working with so far but i'm getting a compile error (method range of object failure).
Private Sub UserForm_Initialize()
Dim range4 As Range
Dim range3 As Range
Dim range2 As Range
Dim range1 As Range
Set range1 = Worksheets(1).Range("MyRange")
Set range2 = Worksheets(2).Range("MyRange2")
Application.Union(Range("range1"), Range("range2")).Select
Selection = range3
range3.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=range4, Unique:=True
Me.lstone.RowSource = range4
End Sub
View 9 Replies
View Related
Mar 8, 2007
Sub New_Book()
Sheets("2006-07").Activate
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("2006-07").Activate
Range("A1").Select
Sheets("2006-07").Select
Range("b3").Select
ActiveCell.FormulaR1C1 = "=R[-2]"
Dim ThisFile As String
Const MyDir As String = "C:"
With ThisWorkbook
ThisFile = .Worksheets("2006-07").Range("b3").Value
. SaveAs Filename:=MyDir & ThisFile
End With
ActiveWorkbook.Save
End Sub
The above VBA works by saving a copy of existing Workbook by refering to cell A1 and then Pasting Special worksheet 2006-07 which has external links. Is it possible to create a looping macro that refers worksheet("BUs") which list all business units I need to run and save? Range(A1) needs have a looping macro that refers worksheet BUs and then automatically saves files without manually changing cell references.
View 6 Replies
View Related
Nov 7, 2013
I am writing a UDF to find the average of two ranges, which start at the StartDate and then go back a certain number of days, that are on another sheet. When I use Union to try and unite my two ranges the resulting range just equals the first range.
VB:
Public Function ModifiedAverage(StartDate As Variant, SheetTenor As String, History As Double)
Dim DateRow, NbCols As Double
DateRow = Application.WorksheetFunction.Match(StartDate, Sheets(SheetTenor).Range("A:A"), 0)
NbCols = Application.WorksheetFunction.CountA(Sheets(SheetTenor).Range("6:6"))
[Code] ....
View 1 Replies
View Related
Aug 15, 2014
I'm writing a function which includes the need to merge 2 ranges into 1 new Range object. The problem is that adding a breakpoint just after this occurs, and viewing the immediates, the new range only actually contains the first input range
For testing, and displaying here I've placed the 2 sub-Ranges into temp objects
[Code]....
The breakpoint is on the next line (not shown), so I can view all the Locals
tempyR1 and tempyR2 both are Range objects containing the correct Range data as expected from the code
However, objExcelRange only contains exactly the same as tempyR2
I'm using the Locals to check as this new combined Range will undergo further processing before being placed onto a sheet, and the combined Range will actually be generated dynamically depending on what options the user picks from a second sheet within the WorkBook - which could in fact be created from between 2 and 5 sub-Ranges
View 7 Replies
View Related
Aug 19, 2006
'How do I use a FOR NEXT loop on a union to just list all cell values in Col A?
'Just need a little help getting a handle on ranges and the union of ranges.
' This is my first time posting a question so any patience is appreciated.
Dim r1 As Range
Dim r2 As Range
Dim myMultipleRange As Range
Dim xCell As Range
Set r1 = Sheets("Sheet1").Range("A1", Range("A65536").End(xlUp))
Set r2 = Sheets("Sheet1").Range("B1", Range("B65536").End(xlUp))
Set myMultipleRange = Union(r1, r2)
r1.Select
For Each xCell In r1
'Ive been using this type of code to access anything I need from a sheet.
Debug.Print r1(xCell.Row, 1), r1(xCell.Row, 2), r1(xCell.Row, 3)
Next xCell...............
View 9 Replies
View Related
Nov 9, 2006
columnA contains account numbers sorted in ascending order i need to use the union method to select all rows where the account number changes so that later i can insert rows between different account numbers in one action. i tried to use the following code but an error occurs stating 424 object required ....
View 7 Replies
View Related
Jun 1, 2007
I have two worksheets sheet1 & sheet2 in Workbook3 both get data from two different workbook1 & workbook2 using Microsoft Queries. Column Headers are same but contentes and no. of rows are different in these sheets. I would like to combine data from these sheets into sheet3 of Workbook3 so that i can create pivot table on that. I tried using Union Method, But it gave me "Run time error '1004'. Method 'Union' of object '_Application' failed in the following line
Set myMultipleRange = Application.Union(r1, r2)
Union method works fine when combining ranges from the same worksheet.
Multiple consolidation in Pivot table is not desirable to me as i have to group data using two columns and i could not get what i wanted using two page fields.
I have created named ranges for each sheet data. Is there an alternative to Union method for combining these named ranges from two worksheets into third sheet through VB code?
View 5 Replies
View Related
Oct 7, 2008
I have the following two ranges in the same spreadsheet: A1:A1000 and B1:B1000. Both contain data that I would like to manipulate. Let's assume I would like to add "1" to every cell in the two ranges. This is what I have so far:
Sub Test2()
Dim wb As Workbook
Dim ws1, ws2 As Worksheet
Dim rng1a, rng1b, rng_union As Range
Set wb = ThisWorkbook
Set ws1 = wb.Worksheets("testsheet")
Set ws2 = wb.Worksheets("result")
ws1.Select
Set rng1 = Range(Cells(1, 1), Cells(1000, 1))
Set rng2 = Range(Cells(1, 2), Cells(1000, 2))
Set rng_union = Union(rng1, rng2)...................
Function ADDONE(rng)
n = rng.Cells.Count
ReDim rng_add(1 To n)
For i = 1 To n
If rng(i) = "" Then GoTo NextIndex
rng_add(i) = rng(i) + 1.............
End Function
I have to somehow combine the two ranges because the data needs to be manipulated simultaneously. Instead of having the range of results returned to me (see worksheetfunction.transpose), I could have calculated the variance, average etc... of the results, too. I'm using the transpose function to show that the operations in function ADDONE are only conducted for the first range of cells (rng1) that I have joined with the union method. I presume that Union might not be the correct method but I don't know ehich other method to use.
View 9 Replies
View Related
Sep 19, 2006
I have 4 sheets. In each sheet, I have a column of data for every hour of every day of one year.
In the 1st worksheet, I want to make a chart using :
- for Y values : the average of the data for each day
- for X values: the day
In the 3 other worksheets,
- for Y values : the data for each hour
- for X values: the hour
To make it more simple, I will first build in the "D" column the data of the average data for each day (so, every 24 columns)
Here is my
Dim lNbSheet As Long ' sheet number
Dim rSheetData As Range ' what will be my Y values
Dim rSheetTime As Range ' what will be my X values
Dim sSheetName As String ' current sheet
For lNbSheet = 1 To 4
'selection of the Y values
Sheets(lNbSheet).Select
sSheetName = ActiveSheet.Name
I get the error "methode SeriesCollectiosn of Object _chart failed;
Also, if you have an idea that could make me avoid writing all the new average-for-the-day data in column D (using it directly),
View 8 Replies
View Related
Jul 15, 2014
I've recorded a Marco copying and pasting information from one cell to other cells and some of the copying functions paste to two cells. I just need this to loop through all information I'm copying from the the new cells.
Range("I1").Select
Selection.Copy
Range("D1").Select
ActiveSheet.Paste
Range("J1").Select
[Code]...
View 7 Replies
View Related
Jun 13, 2013
I have a code in software that exports results to excel. But it stores the numbers associated with indices as text. I need to change all of them to numbers. So I have written the following code, that search through the folder, converts text to numbers and colses the file.
Sub ConvertText2NumberFiles()
Dim v As Variant
Dim rng1 As Range, bk As Workbook
Dim i As Long
ChDrive "C"
ChDir "C: ...analysis"
[Code]....
The problem is it takes time becuase it is going through A LOT OF cells. I only need at most the first 4 columns and the first 2 rows. So I wanted to use the union. I wrote the following:
Set IndexColumns = bk.ActiveSheet.Range(Columns("A") & ":" & Columns("A").SpecialCells(xlLastCell))
Set IndexRows = bk.ActiveSheet.Range(Rows("1") & ":" & Rows("1").SpecialCells(xlLastCell))
Application.Union(Range("IndexColumns"), Range("IndexRows")).Select
Which doesn't work! Morover it is only for one column and one row.
NOTE1 : Like any matrix, the intersection of index columns and index rows is blank!
NOTE2 : The lenght of indices is different from one file to another
View 2 Replies
View Related
Jul 2, 2010
I created a union query in Access to join two tables (Projections and Actual Sales). The query produces the results I want. I need to create a pivot table in Excel using the union query as the source. When I pull up the data import function in Excel, the union query does not appear. Do I need to do something else? I have tried to create a select query where I select all from the union query and I can find that fine.
When I use this query to create the pivot table the results end up all zeros when I try to sum the values. It creates some crazy results when I show it as count of also.
I can provide the data in either the Access database or Excel spreadsheet.
View 4 Replies
View Related
Jul 20, 2012
I have to find the union of 2 columns in excel and club those 2 columns into a single column with values in the increasing order.eg: column 1- 0 2 4.. , column 2- 1,3,5.. final result in column 3 should be 0 1 2 3 4 5...plz let me know the code for this that i can run in VB editor(- excel 2007)
View 9 Replies
View Related
Oct 8, 2008
I'm trying to highlight a bunch of cells in clusters not close together, and then invert the selection so that all cells BUT these are selected (therefore capturing all possible cells that someone could scroll to). In XL03 you could go to File > Invert Selection and it would work fine. But in XL07 which I have now, there doesn't seem to be a way to do it. Also, when using ctrl^a to highlight everything, and while still holding control in XL03 you could de-select specific cells, not so much in 07. I need to know if there's a way to do it with no macros involved. If not, I need a macro to do such a function on any given worksheet.
View 6 Replies
View Related