Help with link

G

gaba

Hi,
I need some help with copying and pasting special (link) the value of one
cell into another.

This is part of the code that I'm using. I've tried almost everything with
the link and is not working

For Each c In Range(ActiveCell.Offset(0, 3).Address, lastC & i + 15)
If c.Interior.ColorIndex = 8 Then
Cells(DestRow, DestCol + 1).Value = c.Value
'I need to link the destination cell with c.value
Cells(DestRow, DestCol + 1).NumberFormat = "0.000"
Cells(DestRow, DestCol + 1).Interior.ColorIndex = 8
End If

Next

Any help would be more than appreciated.
Thanks
 
M

Mike Fogleman

Try something like this (untested, not sure if copy/paste sheet is same or
different)

For Each c In Range(ActiveCell.Offset(0, 3).Address, lastC & i + 15)
If c.Interior.ColorIndex = 8 Then
Range(Address(c)).Copy
Cells(DestRow, DestCol + 1).Select
ActiveSheet.Paste Link:=True
Application.CutCopyMode = False
Cells(DestRow, DestCol + 1).NumberFormat = "0.000"
Cells(DestRow, DestCol + 1).Interior.ColorIndex = 8
End If

Next

Mike F
 
G

gaba

Hi Mike.
Thanks for your answer. I'm getting a compile error (Sub of Function not
define) about the Address. I'll keep trying something else

Gaba
 
D

Dave Peterson

Maybe:

Option Explicit
Sub testme01()

Dim c As Range
Dim lastC As String
Dim i As Long
Dim DestRow As Long
Dim DestCol As Long

'testing only
lastC = "E"
i = 3
DestRow = 3
DestCol = 18

For Each c In Range(ActiveCell.Offset(0, 3), Cells(i + 15, lastC))
If c.Interior.ColorIndex = 8 Then
With Cells(DestRow, DestCol + 1)
.Value = c.Value
'I need to link the destination cell with c.value
.NumberFormat = "0.000"
'or maybe???
.NumberFormat = c.NumberFormat
.Interior.ColorIndex = 8
End With
End If
Next c
End Sub
 
G

gaba

Hi Dave. Glad to see you are around :)
I've tried your changes and still not linking. Is not even taking the value
of c...
Any ideas?
 
D

Dave Peterson

Do you really want a link? Just a formula that points back at that other cell?

With Cells(DestRow, DestCol + 1)
.formula = "=" & c.address(external:=true)
end with

I'm not sure how the destrow/destcol get changed, though.


Hi Dave. Glad to see you are around :)
I've tried your changes and still not linking. Is not even taking the value
of c...
Any ideas?
 
G

gaba

Dave, Thank you so much!
I wish one day I can write my code in such simple yet elegant way
Gaba
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top