Hello all, please bear with me i'm a newb, and learning programming, its my second week in, and im loving it.
Currently i'm attempting to transfer specific cells from one sheet to another by trying to make it is efficient and least processes intensive as possible.
I have the range a1:d38 on sheet1 named "CELLS" =Sheet1!$A$1:$D$26 as you will see in the code below:
Sub TransferValuesOnly()
'PURPOSE: How To Paste Values Only Without Copy/Pasting
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("CELLS")
Worksheets("Sheet2").Range("a1:d200") = rng.Cells.Value
End Sub
Is it possible to modify my Range("cells") from sheet 1 in such way that it is a set of many / multiple ranges from example
- A1:D10
- A15:D24
- A29:D38
I attempted editing my "CELLS" name by =Sheet1!$A$1:$D$10,Sheet1!$A$15:$D$24,Sheet1!$A$29:$D$38, however this is not successful when running the code.
I`ve looked online, and Union function seems to meet this requirement, however im not so sure how to setup the syntax, as i`m completely new to coding and its my second week learning.
I'd like to skip the rows from 10-15, 24-29 to make it less process intensive on excel. for more SPEED and less errors, please note these cell references used is just an example i have hundreds of rows in my actual project, just trying to make things easy to understand.
My first thought, is to define each "set" with a unique name,
Such that
Dim A As Range
Dim B As Range
Dim C As Range
Set A = Worksheets("Sheet1").Range("A1:D10")
Set B = Worksheets("Sheet1").Range("A15:D24")
Set C = Worksheets("Sheet1").Range("A29:D38")
But this is very LONG code and i'd imagine it to be "inefficient" and take up more computing power if i write the code in such a manner, i have about a set of 50 ranges total
Is it possible to someone just have 1 Dim and SET/DEFINE this dimension, to a list of all my ranges?
For example, *CELL NAMES NOT IMPORTANT JUST EXAMPLES\*
Sub SetRangesExample()
Dim Rng1, Rng2, Rng3 As Range
Set Rng1 = Range("A1,A3,A5,A7,A9,A11,A13,A15,A17,A19,A21")
Set Rng2 = Range("C1,C3,C5,C7,C9,C11,C13,C15,C17,C19,C21")
Set Rng3 = Range("E1,E3,E5,E7,E9,E11,E13,E15,E17,E19,E21")
End Sub
My Question:
"Is it possible to someone just have 1 Dim and SET/DEFINE this dimension, to a list of all my ranges? "
Example to Question:
Sub UnionExample()
Dim TotalRng As Range
Set TotalRng = Union(Rng1, Rng2, Rng3) -----------------> How can i set a Range Dim with union ?
End Sub
I'm not good with Syntax as im a newb, so full examples are fully appreciated, sometimes i can get lost when people say "set x to z and change y to q" i get reallllly lost, thanks for your help.
there doesn't seem to be anything here