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: 1
Default If Then Statements HELP!


hi all,

I'm having a slight problem here. I have a macro searching to see if
sheet exists and then copying and pasting information from it to anothe
sheet if it does exist... If it doesn't exist I have a command for
Message Box. The macro works fine until it gets to a sheet tha
doesn't exist at which point it gives me a runtime error "9" "subcrip
out of range" instead of the message box. I'm sure my code could b
much simpler and not so crowded but it's my first macro... hopefull
somebody can help me out.. Thanks a ton!
Here is an excerpt:

Sub Logger()
'
' Logger Macro
' Macro recorded 7/22/2005 by Nati Suchy
'

Sheets("Sheet1").Range("A16:B736").Copy _
Sheets("Temp Data").Range("B9")
Sheets("Sheet1").Range("C16:C736").Copy _
Sheets("RH Data").Range("C9")

' Check to see if more TRH data sheets exist


Dim wSheet As Worksheet

' Data sheet 2

Set wSheet = Sheets("Sheet2")

If wSheet Is Nothing Then 'Doesn't Exist

MsgBox "Please Save file and continue to work"
Set wSheet = Nothing

Else 'Does exist
Sheets("Sheet2").Range("B16:B736").Copy _
Sheets("Temp Data").Range("D9")
Sheets("Sheet2").Range("C16:C736").Copy _
Sheets("RH Data").Range("D9")



' Data Sheet 3


Set wSheet = Sheets("Sheet3")

If wSheet Is Nothing Then 'Doesn't Exist

MsgBox "Please Save file and continue to work"
Set wSheet = Nothing
Else 'Does exist
Sheets("Sheet3").Range("B16:B736").Copy _
Sheets("Temp Data").Range("E9")
Sheets("Sheet3").Range("C16:C736").Copy _
Sheets("RH Data").Range("E9")


' Data Sheet 4

Set wSheet = Sheets("Sheet4")

If wSheet Is Nothing Then 'Doesn't Exist

MsgBox "Please Save file and continue to work"
Set wSheet = Nothing
Else 'Does exist
Sheets("Sheet4").Range("B16:B736").Copy _
Sheets("Temp Data").Range("F9")
Sheets("Sheet4").Range("C16:C736").Copy _
Sheets("RH Data").Range("F9")


' Data Sheet 5

Set wSheet = Sheets("Sheet5")

If wSheet Is Nothing Then 'Doesn't Exist

MsgBox "Please Save file and continue to work"
Set wSheet = Nothing
Else 'Does exist
Sheets("Sheet5").Range("B16:B736").Copy _
Sheets("Temp Data").Range("G9")
Sheets("Sheet5").Range("C16:C736").Copy _
Sheets("RH Data").Range("G9")
End If
End If
End If
End If
End Su

--
natijo
-----------------------------------------------------------------------
natijoe's Profile: http://www.excelforum.com/member.php...fo&userid=2555
View this thread: http://www.excelforum.com/showthread.php?threadid=38988

 
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
If statements DDD Excel Worksheet Functions 1 December 7th 08 11:49 PM
If statements jonssmaster Excel Worksheet Functions 4 November 26th 08 02:58 PM
If statements mjent Excel Worksheet Functions 2 November 20th 08 03:45 AM
IF Statements (Mutliple Statements) Deezel Excel Worksheet Functions 3 October 19th 06 06:13 AM
IF statements Kinggops Excel Discussion (Misc queries) 4 December 2nd 05 10:32 PM


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