Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Benny Benny via OfficeKB.com
 
Posts: n/a
Default Macro "If Then"

I want to use a macro to cut a range of data and place it into a different
worksheet. It looks like this:

Cell A6 is a Validation list with 3 names. Each name represents a set of
data which each have their own named worksheet. The data is keyed into
A7:A15. The 3 types of data need to be sent to the correct worksheet and
pasted at the bottom of the data base, and the cursor needs to be returned
to cell A6 (validation list)of the first sheet.
I can get the macro to run one "If Then arguement", but I do not know how
to tie in the remainding 2 worksheets. Hope I explaine dmy problem
clearly. Thanks for the help.
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Can I use column A of the other worksheet to find the next available cell?

If yes, then maybe something like this will work for you:

Option Explicit
Sub testme()

Dim otherWks As Worksheet
Dim RngToCopy As Range
Dim DestCell As Range
Dim CurWks As Worksheet
Dim keyCell As Range

Set CurWks = ActiveSheet

With CurWks
Set keyCell = .Range("a6")
Set otherWks = Nothing
On Error Resume Next
Set otherWks = Worksheets(keyCell.Value)
On Error GoTo 0
If otherWks Is Nothing Then
MsgBox "Invalid entry in: " & keyCell.Address(0, 0)
Exit Sub
End If

Set RngToCopy = .Range("a7:A15")
With otherWks
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

RngToCopy.Copy _
Destination:=DestCell

RngToCopy.ClearContents '???

keyCell.ClearContents 'maybe ???

End With

End Sub

I'd put a button from the Forms toolbar near A6 and then after I made my choice,
added my data, I'd click the button.

The code does expect the worksheet names to match the entries in the
Data|Validation list in A6.

"Benny Benny via OfficeKB.com" wrote:

I want to use a macro to cut a range of data and place it into a different
worksheet. It looks like this:

Cell A6 is a Validation list with 3 names. Each name represents a set of
data which each have their own named worksheet. The data is keyed into
A7:A15. The 3 types of data need to be sent to the correct worksheet and
pasted at the bottom of the data base, and the cursor needs to be returned
to cell A6 (validation list)of the first sheet.
I can get the macro to run one "If Then arguement", but I do not know how
to tie in the remainding 2 worksheets. Hope I explaine dmy problem
clearly. Thanks for the help.


--

Dave Peterson
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
Macro and sub rountines The Good Deeds Team Excel Discussion (Misc queries) 1 March 23rd 05 11:26 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
automatic macro update boconnell Excel Worksheet Functions 4 February 9th 05 07:10 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM


All times are GMT +1. The time now is 05:27 PM.

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"