Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Need help with writing variant back to sheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help with writing variant back to sheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Allow only writing in a protected Sheet Piruzzi Setting up and Configuration of Excel 1 January 5th 09 11:59 PM
Writing formulas between sheet Dave Excel Discussion (Misc queries) 4 February 22nd 07 05:50 PM
Writing data back via a userform Steph[_3_] Excel Programming 3 August 10th 04 04:39 PM
Writing a macro to bring back distinct value Sean[_7_] Excel Programming 2 May 24th 04 01:14 PM
4 variables to one sheet, then back to original sheet with answer Howard Excel Programming 1 January 3rd 04 09:17 PM


All times are GMT +1. The time now is 01:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"