Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Subscript out of Range" Error Msg?


Hi guys,
could you pls have a look at my code and let me know why i keep getting
this error msg every time i try to execute it?

Thanks so much,
Maria

Sub CommandButtonDRG_Click()


Dim i As Integer
Dim curCell As Date
Dim startDate As Date
Dim endDate As Date

Dim SheetNumber As Integer

SheetNumber = "949"

startDate = Sheets(SheetNumber).Range("c2").Value
endDate = Sheets(SheetNumber).Range("e2").Value
Sheets(SheetNumber).Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"

Sheets(SheetNumber).Range("c2").Select
ActiveCell.FormulaR1C1 = startDate

i = 3
Do
curCell = Sheets(SheetNumber).Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=dvstradedate(R[-1]C,1)"
i = i + 1
Loop Until Sheets(SheetNumber).Cells(i - 1, 3).Value = endDate
End

End Sub


--
mariasa
------------------------------------------------------------------------
mariasa's Profile: http://www.excelforum.com/member.php...o&userid=31726
View this thread: http://www.excelforum.com/showthread...hreadid=523076

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default "Subscript out of Range" Error Msg?

Dim SheetNumber As String

HTH
--
AP

"mariasa" a écrit
dans le message de
...

Hi guys,
could you pls have a look at my code and let me know why i keep getting
this error msg every time i try to execute it?

Thanks so much,
Maria

Sub CommandButtonDRG_Click()


Dim i As Integer
Dim curCell As Date
Dim startDate As Date
Dim endDate As Date

Dim SheetNumber As Integer

SheetNumber = "949"

startDate = Sheets(SheetNumber).Range("c2").Value
endDate = Sheets(SheetNumber).Range("e2").Value
Sheets(SheetNumber).Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"

Sheets(SheetNumber).Range("c2").Select
ActiveCell.FormulaR1C1 = startDate

i = 3
Do
curCell = Sheets(SheetNumber).Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=dvstradedate(R[-1]C,1)"
i = i + 1
Loop Until Sheets(SheetNumber).Cells(i - 1, 3).Value = endDate
End

End Sub


--
mariasa
------------------------------------------------------------------------
mariasa's Profile:

http://www.excelforum.com/member.php...o&userid=31726
View this thread: http://www.excelforum.com/showthread...hreadid=523076



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Subscript out of Range" Error Msg?


Thanks, but I tried that, and now I get the "Application-defined o
object-defined error" msg :-

--
marias
-----------------------------------------------------------------------
mariasa's Profile: http://www.excelforum.com/member.php...fo&userid=3172
View this thread: http://www.excelforum.com/showthread.php?threadid=52307

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default "Subscript out of Range" Error Msg?

To answer your question, this would be better.
Sub ft()
Set SheetNumber = Sheets("sheet1")
MsgBox SheetNumber.Range("a1")
End Sub

But you can't select the way you did. try something like
with sheets("sheet1")
startDate = .Range("c2")
endDate = .Range("e2")
..Columns("C:C").NumberFormat = "m/d/yyyy"
..Range("c2")=startDate '???
end with



--
Don Guillett
SalesAid Software

"mariasa" wrote in
message ...

Hi guys,
could you pls have a look at my code and let me know why i keep getting
this error msg every time i try to execute it?

Thanks so much,
Maria

Sub CommandButtonDRG_Click()


Dim i As Integer
Dim curCell As Date
Dim startDate As Date
Dim endDate As Date

Dim SheetNumber As Integer

SheetNumber = "949"

startDate = Sheets(SheetNumber).Range("c2").Value
endDate = Sheets(SheetNumber).Range("e2").Value
Sheets(SheetNumber).Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"

Sheets(SheetNumber).Range("c2").Select
ActiveCell.FormulaR1C1 = startDate

i = 3
Do
curCell = Sheets(SheetNumber).Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=dvstradedate(R[-1]C,1)"
i = i + 1
Loop Until Sheets(SheetNumber).Cells(i - 1, 3).Value = endDate
End

End Sub


--
mariasa
------------------------------------------------------------------------
mariasa's Profile:
http://www.excelforum.com/member.php...o&userid=31726
View this thread: http://www.excelforum.com/showthread...hreadid=523076



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default "Subscript out of Range" Error Msg?

Try dimming it as a long and removing the quotes from around it (unless it's
really named "929").

hth,

Doug


"mariasa" wrote in
message ...

Thanks, but I tried that, and now I get the "Application-defined or
object-defined error" msg :-(


--
mariasa
------------------------------------------------------------------------
mariasa's Profile:
http://www.excelforum.com/member.php...o&userid=31726
View this thread: http://www.excelforum.com/showthread...hreadid=523076





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Subscript out of Range" Error Msg?


Thanks for the suggestion. I tried this, following ur advice. But i
still gives me the error message - really annoying.

Best,
Maria

Sub CommandButtonDRG_Click()


Dim i As Integer
Dim curCell As Date
Dim startDate As Date
Dim endDate As Date



With Sheets("943")


startDate = Range("c2").Value
endDate = Range("e2").Value
Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"

Range("c2").Select
ActiveCell.FormulaR1C1 = startDate

i = 3
Do
curCell = Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=dvstradedate(R[-1]C,1)"
i = i + 1
Loop Until Cells(i - 1, 3).Value = endDate
End
End With


End Su

--
marias
-----------------------------------------------------------------------
mariasa's Profile: http://www.excelforum.com/member.php...fo&userid=3172
View this thread: http://www.excelforum.com/showthread.php?threadid=52307

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Subscript out of Range" Error Msg?


Actually doing it with the String object works /see code below. So
seem to be all set. Thanks, guys!!! :-)

Best,
Maria


Sub CommandButtonDRG_Click()


Dim i As Integer
Dim curCell As Date
Dim startDate As Date
Dim endDate As Date

Dim SheetNumber As String

SheetNumber = "943"

startDate = Sheets(SheetNumber).Range("c2").Value
endDate = Sheets(SheetNumber).Range("e2").Value
Sheets(SheetNumber).Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"

Sheets(SheetNumber).Range("c2").Select
ActiveCell.FormulaR1C1 = startDate

i = 3
Do
curCell = Sheets(SheetNumber).Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=dvstradedate(R[-1]C,1)"
i = i + 1
Loop Until Sheets(SheetNumber).Cells(i - 1, 3).Value = endDate
End

End Su

--
marias
-----------------------------------------------------------------------
mariasa's Profile: http://www.excelforum.com/member.php...fo&userid=3172
View this thread: http://www.excelforum.com/showthread.php?threadid=52307

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
"Subscript out of range" error for: Workbooks("Test1.xls").Save Just12341234 Excel Programming 2 June 17th 05 03:16 PM
FileCopy Command Giving "Subscript Out of Range" Error Message Jim Hagan Excel Programming 2 June 15th 05 06:07 PM
"Subscript out of range Runtime Error 9" teresa Excel Programming 1 December 14th 04 10:22 PM
SaveAs "subscript out of range" error (COM - SOAP) Matthia Excel Programming 0 July 11th 03 07:01 AM
SaveAs "subscript out of range" error (COM - SOAP) jaf Excel Programming 0 July 10th 03 07:59 PM


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