Hi
I have 2 defined ranges named 'X' and 'Y' (via Insert>Name>Define). X is A1:F1. Y is B1:F1.
I'm quite new to Names, so aren't familiar with the VBA.
So far I've manged to clear the range via
I'd now like code that copies each of the values in Y into X. However, I need to do this cell-by-cell, rather than in 1 go. This is because there are linkages between rows A and B. Ie, changing cell A1 will result in a change to B2, changes to A2 will change C3, etc.Code:ThisWorkbook.Names("X").RefersToRange.ClearContents
Hope this is clear, but please let me know if it isn't.
Thanks in advance
Hi pctuk
use something like
this result will be in the Immediate paneCode:Sub ptest() Z = ThisWorkbook.Names("x").RefersToRange.Value For Each w In Z Debug.Print w Next End Sub
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
Thanks very much for the reply. Just for reference, I think I've cracked it:-
PaulCode:Sub Macro() Dim Destination As Range Dim Source As Range Set Destination = ThisWorkbook.Names("X").RefersToRange Set Source = ThisWorkbook.Names("Y").RefersToRange Destination.ClearContents For i = 1 To 10 Step 1 Destination(1, i) = Source(1, i) Next i End Sub
Excellent!
You can also
use Ubound to find the last value
Code:Sub ptest() Z = ThisWorkbook.Names("x").RefersToRange.Value For w = 1 To UBound(Z) Debug.Print w Next End Sub
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks