View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Max C Max C is offline
external usenet poster
 
Posts: 6
Default Setting the text in a cell to the text of a cell on a different sheet in the same workbook

I just wanted to get back to everyone to say I finally played with this
freakin' thing long enough to get it to work. I honestly don't know
what combination of changes finally made it work, but I know it had
something to do with removing the ".text" property of the ranges I was
referencing in the sheet the text was supposed to be copied to. Here's
the resulting code.
___________________________
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A14:A35")) Is Nothing Then
If Target.Value < 1 Or Target.Value 180 Then
Range("C" & Target.Row & ":I" & Target.Row) = ""
Else
Range("C" & Target.Row & ":I" & Target.Row) =
Sheets("Info").Range("D" & _
(Target.Value + 24)).Text
End If
End If
End Sub
___________________________

Jeez, it looks so simple now. I'm embarassed that it took me this long
to figure it out.

Perhaps that'll help someone in the future. I can't be the first
person that's ever wanted to do this.

Max.


Max C wrote:
Tom Ogilvy wrote:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim SelectedText As String
On Error goto ErrHandler
If Not Intersect(Target(1), Range("A14:A35")) Is Nothing Then
Application.EnableEvents = False
SelectedText = Sheets("Info").Range("D" & (Target(1).Value _
+ 24) & ":J" & (Target(1).Value + 24)).Text
Range("C" & Target(1).Row & ":I" & Target(1).Row).Text = SelectedText
End If
ErrHandler:
Application.EnableEvents = True
End Sub

as to not working, it sounds like you have some code that disables events
and then does not turn them back on.

To test, run this macro

Sub ABC()
Application.EnableEvents = True
End Sub

after running that does the event macro start working?

This assumes you don't have security set to high and macros are silently
disabled.

--
Regards,
Tom Ogilvy


Tom, thanks once again for the attempted help, but I really don't
understand what your additions are supposed to do. I see that you put
"(1)" after each "Target" but it didn't seem to change anything. Also,
after the "If not" line you included "Application.EnableEvents = False"
before the line that does the actual work. I probably just don't
understand how VB reads this, but wouldn't that prevent the next line
from working at all?

At any rate, when I ran your code as it is, my worksheet didn't do
anything. I'd type in a number and nothing else would happen. When I
commented out the lines dealing with "Application.EnableEvents = " I
again got the "Invalid use of null" error.

I can't believe that what I'm trying to do could be so hard. It seems
like this would be a fairly common task.

Oh, and by the way, you were right about the Macros thing. I didn't
realize there was a security setting. I put it back to medium and now
all is well.

Thanks for everything.

Mark.