Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VBA script to add text to cell.

Is there a VBA script that can add text to cell depending on choice from drop
down menu. Not the same "exact" letters as the coice from the drop down menu
though... already know how to do that.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA script to add text to cell.

Hi Calle,

Your question is unclear.

Perhaps, however the following will help you.

Assume that cells A10:A10 have a data validation list applied and that the
list includes three values: Anne, Ben Carol.

Try something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

Set rng = Intersect(Range("A1:A10"), Target)

If Not rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
With rng
Select Case LCase(.Value)
Case "anne": .Value = "Anne-Marie"
Case "ben": .Value = "Benjamin"
Case Else: .Value = "Invalid Entry!"
End Select
End With
End If

XIT:
Application.EnableEvents = True

End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"Calle" wrote in message
...
Is there a VBA script that can add text to cell depending on choice from
drop
down menu. Not the same "exact" letters as the coice from the drop down
menu
though... already know how to do that.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VBA script to add text to cell.

Hi! thx for the response.
That's about it but I want the new text in another cell...
How do I do that
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA script to add text to cell.

Hi Calle,

Hi! thx for the response.
That's about it but I want the new text in another cell...
How do I do that


Try something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

Set rng = Intersect(Range("A1:A10"), Target)

If Not rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
With rng
Select Case LCase(.Value)
Case "anne": .Offset(0, 1).Value = "Anne-Marie"
Case "ben": .Offset(0, 1).Value = "Benjamin"
Case Else: .Offset(0, 1).Value = "Invalid Entry!"
End Select
End With
End If

XIT:
Application.EnableEvents = True

End Sub
'<<=============

This will place the new text in the next column. To place the text
elsewhere, simply amend the offset co-ordinates or stipulate the required
address(es).


---
Regards,
Norman


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VBA script to add text to cell.

thx for your time. it worked great
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
How to generate a text file from Excel using a macro or script? Frank Excel Discussion (Misc queries) 0 January 6th 08 05:11 PM
Text Box Change Script [email protected] Excel Programming 2 April 24th 06 11:38 PM
A script to write in missing text Crowbar via OfficeKB.com Excel Programming 1 October 31st 05 03:35 PM
A script to write in missing text Crowbar via OfficeKB.com Excel Programming 0 October 31st 05 03:26 PM
Script to add hyperlink to Excel cell containing text John Doe[_5_] Excel Programming 4 October 11th 04 02:26 AM


All times are GMT +1. The time now is 12:13 AM.

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

About Us

"It's about Microsoft Excel"