Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default LinkedCell problem

Hi experts.

I have a problem with a checkbox' linkedcell. - the following code
works as a charm - but if I want to change the reference to another
sheet, it doesn't work (sub test2)


'------------------- Code that works ---------------

Sub test()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top,
myRange.Width, myRange.Height).Select
With Selection
.LinkedCell = rng(1, 1).Address
.Characters.Text = "Test"
End With

End Sub

'------------------- Code that does NOT works ---------------

Sub test2()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top,
myRange.Width, myRange.Height).Select
With Selection
.LinkedCell = Sheets("Sheet1").rng(1, 1).Address
.Characters.Text = "Test"
End With

End Sub

Can anybody help me?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default LinkedCell problem

Try this:-


Sub test2()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top, _
myRange.Width, myRange.Height).Select

With Selection
.LinkedCell = "Sheet1!$A$1"
.Characters.Text = "Test"
End With
End Sub


Mike

"TFriis" wrote:

Hi experts.

I have a problem with a checkbox' linkedcell. - the following code
works as a charm - but if I want to change the reference to another
sheet, it doesn't work (sub test2)


'------------------- Code that works ---------------

Sub test()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top,
myRange.Width, myRange.Height).Select
With Selection
.LinkedCell = rng(1, 1).Address
.Characters.Text = "Test"
End With

End Sub

'------------------- Code that does NOT works ---------------

Sub test2()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top,
myRange.Width, myRange.Height).Select
With Selection
.LinkedCell = Sheets("Sheet1").rng(1, 1).Address
.Characters.Text = "Test"
End With

End Sub

Can anybody help me?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default LinkedCell problem

On 27 Nov., 13:04, Mike H wrote:
Try this:-

Sub test2()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top, _
myRange.Width, myRange.Height).Select

With Selection
.LinkedCell = "Sheet1!$A$1"
.Characters.Text = "Test"
End With
End Sub

Mike


That works fine.. Dunno why, but I have tested this a 100 time :S

But it works now - thanks :)

Sub test2()

Dim rng As Range
Dim myRange As Range

'On Error Resume Next

Dim shname As String
shname = "Sheet2"

Set myRange = Range("A10")
Set rng = Range("A1:D1")

ActiveSheet.CheckBoxes.Add(myRange.Left, myRange.Top,
myRange.Width, myRange.Height).Select
With Selection
.LinkedCell = shname & "!" & rng(1, 1).Address
.Characters.Text = "Test"
End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default LinkedCell problem

New problem though, if the sheetname is something like:

Dim shname = "Sheet 2" '(with a space between t and 2)

Then it doesn't work again - solutions anyone?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default LinkedCell problem

On 27 Nov., 13:23, TFriis wrote:
New problem though, if the sheetname is something like:

Dim shname = "Sheet 2" '(with a space between t and 2)

Then it doesn't work again - solutions anyone?


Ok something like this works:

..LinkedCell = "'" & shname & "'" & "!" & rng(1, 1).Address

But I don't really get it :/
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
setting LinkedCell using VBA michael.beckinsale Excel Programming 2 September 1st 06 04:20 PM
Export Linkedcell racerman Excel Programming 2 September 5th 05 08:39 PM
Linkedcell protection problem Karin New Users to Excel 2 June 24th 05 12:03 AM
LinkedCell Update does not always respond Jeroen Kluytmans Excel Programming 4 April 16th 04 08:58 AM
Linkedcell Problems... cornishbloke[_25_] Excel Programming 3 January 21st 04 02:45 PM


All times are GMT +1. The time now is 08:47 AM.

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

About Us

"It's about Microsoft Excel"