Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have some code that makes use of a variant to transfer a column of
data on one worksheet to a diagonal set of cells on another sheet. I basically loop and assign the column data to the diagonals to the variant, then equate the variant back to the new sheet (as a whole block). Here's my issue: I have formulas on the new sheet that I would like to retain (that are on the off diagonals), but when I assign the variant to the new sheet (since it's the complete block), it's overwriting the formulas. Is there a way to put the values on the sheet and retain the formulas? Maybe creating the variant as a diagonal range in the first place? I wasnt having much luck with that. Thanks for the help! --- Message posted from http://www.ExcelForum.com/ |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
bri0710 < wrote:
I have some code that makes use of a variant to transfer a column of data on one worksheet to a diagonal set of cells on another sheet. I basically loop and assign the column data to the diagonals to the variant, then equate the variant back to the new sheet (as a whole block). Here's my issue: I have formulas on the new sheet that I would like to retain (that are on the off diagonals), but when I assign the variant to the new sheet (since it's the complete block), it's overwriting the formulas. Is there a way to put the values on the sheet and retain the formulas? Maybe creating the variant as a diagonal range in the first place? I wasnt having much luck with that. Thanks for the help! --- Message posted from http://www.ExcelForum.com/ Sub Test12345() Set rng1 = Sheets(10).Range("A1:A10") Set rng = Sheets(9).Range("A1") For i = 1 To 10 Set rng = Union(rng, Range("a1")(i, i)) Next k = 1 For Each iCell In rng iCell.Value = rng1(k) k = k + 1 Next End Sub Alan Beban |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
a refinement might be:
Sub Test12345() Dim rng as Range rng1 as Rang, i as Long Set rng1 = Sheets(10).Range("A1:A10") Set rng = Sheets(9).Range("A1") For i = 1 To 10 rng(i,i).Value = rng1(i).Value Next End Sub Also doesn't require Sheet(9) to be the active sheet. -- Regards, Tom Ogilvy "Alan Beban" wrote in message ... bri0710 < wrote: I have some code that makes use of a variant to transfer a column of data on one worksheet to a diagonal set of cells on another sheet. I basically loop and assign the column data to the diagonals to the variant, then equate the variant back to the new sheet (as a whole block). Here's my issue: I have formulas on the new sheet that I would like to retain (that are on the off diagonals), but when I assign the variant to the new sheet (since it's the complete block), it's overwriting the formulas. Is there a way to put the values on the sheet and retain the formulas? Maybe creating the variant as a diagonal range in the first place? I wasnt having much luck with that. Thanks for the help! --- Message posted from http://www.ExcelForum.com/ Sub Test12345() Set rng1 = Sheets(10).Range("A1:A10") Set rng = Sheets(9).Range("A1") For i = 1 To 10 Set rng = Union(rng, Range("a1")(i, i)) Next k = 1 For Each iCell In rng iCell.Value = rng1(k) k = k + 1 Next End Sub Alan Beban |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the help!
I was hoping to use variants for the speed benefit, but this will work. I'm stuck with a slower PC, and just doing 200 cells takes 60 seconds. --- Message posted from http://www.ExcelForum.com/ |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can't lay down a 2D array and only overwrite some of the cells in the
target. You could pick up the source area, pick up the destination area, update the array for the destination area, then put it back down. Sub Test12345() Dim rng As Range, rng1 As Range, i As Long Dim varr as Variant, varr1 as Variant Set rng1 = Sheets(2).Range("A1:A10") Set rng = Sheets(3).Range("A1").Resize(10, 10) varr1 = rng1.Value varr = rng.Formula For i = 1 To 10 varr(i, i) = varr1(i, 1) Next rng.Value = varr End Sub -- Regards, Tom Ogilvy "bri0710 " wrote in message ... Thanks for the help! I was hoping to use variants for the speed benefit, but this will work. I'm stuck with a slower PC, and just doing 200 cells takes 60 seconds. --- Message posted from http://www.ExcelForum.com/ |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
bri0710 < wrote:
Thanks for the help! I was hoping to use variants for the speed benefit, but this will work. I'm stuck with a slower PC, and just doing 200 cells takes 60 seconds. --- Message posted from http://www.ExcelForum.com/ Could you first transfer the entire block of formulas to the array, then load the diagonal of the array, then transfer the whole array back to the sheet? Alan Beban |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That's a good idea actually.
I tried to assign the array to the range with the .Formula tag, but I' getting the "Can't assign to array" error when it gets to that line. Is there a better way (aside from using a loop) to assign a shee filled with formulas to an variant array? Thank -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Allow only writing in a protected Sheet | Setting up and Configuration of Excel | |||
Writing formulas between sheet | Excel Discussion (Misc queries) | |||
Writing data back via a userform | Excel Programming | |||
Writing a macro to bring back distinct value | Excel Programming | |||
4 variables to one sheet, then back to original sheet with answer | Excel Programming |