View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
scott[_10_] scott[_10_] is offline
external usenet poster
 
Posts: 5
Default insert Worksheet_SelectionChange(ByVal Target As Range) through vba

Thanks for the offer of assistance. I will play with DoEvents.

I am inserting a sample of what I do have. I am sure you realize this
is called from another procedure and their are other things going on.
And since I have only learned this by trial and error my code may not
be written very well.

Sub Record_SKUs()

Dim VBCodeMod As CodeModule
Dim LineNum As Long
Set VBCodeMod =
ActiveWorkbook.VBProject.VBComponents("Sheet1").Co deModule
With VBCodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Public ad_str, frm_ad" & Chr(13) & _
"" & Chr(13) & _
"Private Sub Worksheet_SelectionChange(ByVal Target As Range)" &
Chr(13) & _
"Dim tmpObj, strObj" & Chr(13) & _
"On Error Resume Next" & Chr(13) & _
"strObj = frm_ad" & Chr(13) & _
"If ActiveCell.Column = 7 Then" & Chr(13) & _
"Range(strObj).Offset(0, 7) = Left(ad_str, 3) & ""0""" & Chr(13) & _
"Range(strObj).Offset(0, 8) = Right(ad_str, 5)" & Chr(13) & _
"End If" & Chr(13) & _
"If ActiveCell.Column = 7 And ActiveCell.Row < 1 Then" & Chr(13) & _
"ad_str = ActiveCell" & Chr(13) & _
"frm_ad = ActiveCell.Address" & Chr(13) & _
"End If" & Chr(13) & _
"End Sub"
End With
End Sub