LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Problem with VB running from a command button

[win 2k, office 2k]

I have some VB which takes a filtered list (sheet 1), pastes the values to a
new sheet (sheet 2), then sorts it (another sheet (sheet 3) has a chart
which is based on sheet 2 values). the process is started by clicking a
command button on sheet 1.

everything works until the sorting stage, but it constantly wants to refer
to the first sheet (which contains the command button). how can i make the
sorting stage refer to the correct sheet?

(code is below...)

Many thanks,

tim


Code

Private Sub CommandButton4_Click()

Dim Xfer, Data

'sheet 2
Set Xfer = Worksheets("Transfer")

'sheet 1
Set Data = Worksheets("Data")

'sheet 2
Xfer.Select
Xfer.Range("A1").Select
Selection.CurrentRegion.Select
Selection.ClearContents

'sheet 1
Data.Select
Data.Range("A2").Select
Selection.CurrentRegion.Select
Selection.Copy
Range("A1").Select

'sheet 2
Xfer.Select
Xfer.Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False

Sheets("Transfer").Select
Xfer.Range("B2").Select
'this is where the problem is
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


 
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
Command to make a forumula fron not running boxterduke Excel Discussion (Misc queries) 2 November 3rd 08 09:46 PM
Command Button Problem albertmb Excel Discussion (Misc queries) 6 June 22nd 08 01:06 PM
Problem with command button name Jason[_9_] Excel Discussion (Misc queries) 10 October 19th 07 09:54 PM
Checking to see that a CHART exists prior to running a simple command Anton Excel Discussion (Misc queries) 0 August 29th 06 06:30 AM
strange command button problem David Excel Discussion (Misc queries) 0 March 20th 06 03:06 PM


All times are GMT +1. The time now is 09:50 PM.

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"