Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default failure in sheet with macro

I have( with help of this forum) written a macro in which a range of columns
is selected and deleted depending on the amount of worksheets in the workbook.
The VBA code is:
Dim result As Long

result = Application.InputBox("Enter Number of Days which are in this
report( highest number of worksheets in document", "BPC Performance
Calculator")

Select Case result
Case 1
Columns("T:CJ").Select
Case 2
Columns("U:CJ").Select
Case 3
Columns("V:CJ").Select
Case 4
Columns("W:CJ").Select
Case 5
Columns("X:CJ").Select
Case 6
Columns("Y:CJ").Select
Case 7
Columns("Z:CJ").Select
Case 8
Columns("AA:CJ").Select
Case 9
Columns("AB:CJ").Select

Etc etc

Case 68
Columns("CI:CJ").Select
Case 69
Columns("CJ:CJ").Select
Case 70
Columns("CZ:CZ").Select
Case Else
MsgBox "please enter a valid number", , "BPC Performance
Calculator"
Exit Sub

End Select
Selection.ClearContents
Range("A1").Select


Now this works perfect, unless if there is only 1 worksheet in the file(
Case 1). In this situation columns S:CJ are selected and deleted. I do not
understand and can't figure it out.
Does anyone have an idea?
if needed I can send the file by email.

thanks.

Chris



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default failure in sheet with macro

don't know about the #1 case, but you could shorten/simplify your code using
something like:

activesheet.range(Cells(1,19+result),cells(1,88)). entirecolumn.clearcontents

(assuming your case 70 was a typo)

Tim


"Chris D" wrote in message
...
I have( with help of this forum) written a macro in which a range of
columns
is selected and deleted depending on the amount of worksheets in the
workbook.
The VBA code is:
Dim result As Long

result = Application.InputBox("Enter Number of Days which are in this
report( highest number of worksheets in document", "BPC Performance
Calculator")

Select Case result
Case 1
Columns("T:CJ").Select
Case 2
Columns("U:CJ").Select
Case 3
Columns("V:CJ").Select
Case 4
Columns("W:CJ").Select
Case 5
Columns("X:CJ").Select
Case 6
Columns("Y:CJ").Select
Case 7
Columns("Z:CJ").Select
Case 8
Columns("AA:CJ").Select
Case 9
Columns("AB:CJ").Select

Etc etc

Case 68
Columns("CI:CJ").Select
Case 69
Columns("CJ:CJ").Select
Case 70
Columns("CZ:CZ").Select
Case Else
MsgBox "please enter a valid number", , "BPC Performance
Calculator"
Exit Sub

End Select
Selection.ClearContents
Range("A1").Select


Now this works perfect, unless if there is only 1 worksheet in the file(
Case 1). In this situation columns S:CJ are selected and deleted. I do not
understand and can't figure it out.
Does anyone have an idea?
if needed I can send the file by email.

thanks.

Chris





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 Failure Paula Excel Discussion (Misc queries) 6 March 5th 09 05:50 PM
Ctrl+Home failure when sheet protected Drew[_2_] Excel Discussion (Misc queries) 1 March 19th 08 06:18 AM
unprotect sheet failure Eric[_33_] Excel Programming 3 December 23rd 07 03:35 PM
Copying objects to new sheet failure Steven Excel Discussion (Misc queries) 0 July 25th 07 02:50 PM
Chart versus Work Sheet Code Failure Nigel Excel Programming 2 April 18th 05 05:16 PM


All times are GMT +1. The time now is 01: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"