excel vba question

  • Thread starter Thread starter levy.pate
  • Start date Start date
L

levy.pate

Is there any excel vba code that will accomplish the following:

I have data entered in cells A1 thru E1 lets say (Name, Address, Zip,
Country, and Phone). What I would like to be able to do is enter the
requested information directly in the cells that contain the info as
mentioned above. Then if I make a mistake or delete the info I typed in
all together the original data returns. Example, In cell B2 it shows
Address, so if I type in my address the word Address is replaced with
my acutal address however, if I deleted my address the word Address
would reappear. Hope someone out there understands this and is able to
provide a solution if there is one. Thanks in advance.
 
This an Access newsgroup - this question should be addressed to
"microsoft.public.excel.programming"

But FWIW, you need to trap the event change on the sheet and handle
that. Place the following code in the Worksheet code module. (Note I've
created two constants so you can restrict the behaviour to between
specific columns.

Private Const ColToStartThisBehaviourAt As Integer = 1
Private Const ColToStopThisBehaviourAt As Integer = 5

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range

'prevent any changes we make from firing events here
Application.EnableEvents = False
For Each c In Target.Cells
With c
If .Column >= ColToStartThisBehaviourAt And _
.Column <= ColToStopThisBehaviourAt Then
If .Row > 1 Then
If Len(.Value) = 0 Then
.Value = Me.Cells(1, .Column)
End If
End If
End If
End With
Next c
Application.EnableEvents = True
End Sub
 

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

Back
Top