Thread: Macro Help
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Simon Lloyd[_1232_] Simon Lloyd[_1232_] is offline
external usenet poster
 
Posts: 1
Default Macro Help


Hi David, firstly you cant simply change the name of the sub and still
keep (ByVal Target AS Range) (thats a worksheet event code), what you
can do is change TARGET to activecell and ME to the sheet you are
working from in this format Sheets("Sheet1") get rid of the ByVal
....etc and then assign the macro item1 to your button.

David;456620 Wrote:
I am using a macro Simon wrote. Its written to format an address field
depending upon a cell value. This macro executes randomly. I would like
to convert it to a button click. So the user can execute it themselves
when they need it. I need help in converting this code to a code for a
button (Button266_Click).

Thanks for all your help.


Code:
--------------------

Sub item1(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Target.Address < "$H$12" Then Exit Sub
If Me.Range("H12") < "" Then
With Sheets("Letter1")
.Range("B67").Value = Me.Range("H11").Value
.Range("B68").Value = " " & Me.Range("H6").Value
.Range("B69").Value = Me.Range("H12").Value
.Range("B70").Value = Me.Range("a600").Value & " "
.Range("B70").Value = Me.Range("H13").Value & ", " _
& Me.Range("I13").Value & ", " _
& Me.Range("J13").Value
End With
Else
With Sheets("Letter1")
.Range("B67").Value = Me.Range("H6").Value
.Range("B68").Value = Me.Range("H9").Value
.Range("B69").Value = Me.Range("H10").Value & ", " _
& Me.Range("I10").Value & ", " _
& Me.Range("J10").Value
.Range("B70").Value = Me.Range("a600").Value & " "
End With
End If
End Sub

--------------------



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=126388