#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel marco

I need to be able to enter data in one cell and run a macro where
excel would move that data to a worksheet of the same name.

Example: enter 1234 into cell A1. run macro. Cell A1 contents are
transferred to worksheet 1234

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default excel marco

so sheet 1234 would eventually end up with a bunch of cells containing 1234

Right click on the sheet tab where you will enter data in cell A1 and select
view code. Paste in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh as Worksheet, rng as Range
If Target.Address = "$A$1" then
on Error resume Next
set sh = worksheets(Target.value)
On error goto 0
if not sh is nothing then
if sh.Name = me.Name then exit sub
set rng = sh.Cells(rows.count,1).End(xlup)(2)
rng.value = target.value
on Error goto ErrHandler
Application.EnableEvents = False
Target.ClearContents
end if
end if
ErrHandler:
Application.EnableEvents = True
End Sub

Adapt to suit your real needs.

--
Regards,
Tom Ogilvy

" wrote:

I need to be able to enter data in one cell and run a macro where
excel would move that data to a worksheet of the same name.

Example: enter 1234 into cell A1. run macro. Cell A1 contents are
transferred to worksheet 1234


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default excel marco

Copy these two code blocks into a standard module:

Sub Foo()
Dim Temp As String
If ActiveCell = Range("a1") Then
Temp = Range("A1").Value
If SheetExists(Temp) Then
Range("A1").Copy Destination:=Sheets(Temp).Range("A1")
Else
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = Temp
Range("A1").Value = Temp
End If
End If
End Sub

Private Function SheetExists(sname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then SheetExists = True _
Else SheetExists = False
End Function

In sheet1 - cell A1 enter jkuck
Run macro Foo

Hope this helps,
Jim May



" wrote in message
ups.com:

I need to be able to enter data in one cell and run a macro where
excel would move that data to a worksheet of the same name.

Example: enter 1234 into cell A1. run macro. Cell A1 contents are
transferred to worksheet 1234


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
Excel Marco for IP Address [email protected] Excel Worksheet Functions 1 August 17th 06 07:05 PM
marco problem in excel 97 Jimmy Excel Programming 2 April 12th 06 09:30 AM
how to use marco in excel rnparikh New Users to Excel 9 August 2nd 05 12:08 AM
excel Marco question ... need help please ALP Excel Discussion (Misc queries) 3 March 1st 05 03:11 PM
Excel marco upgrade DaveBerk Excel Programming 0 December 15th 04 01:37 PM


All times are GMT +1. The time now is 09:25 AM.

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

About Us

"It's about Microsoft Excel"