Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
christophe meresse
 
Posts: n/a
Default What's wrong with my code ?



Hi !

I'm trying this code but I have a code error 9
Can you help me ?


Private Sub Cmd_Valid_Click()
Dim c As Integer
c = 1
For c = 1 To 12
If Range("R28").Value = c Then
Zone = "Feuil" & c + 4
End If
Next c
MsgBox "Selected sheet is" & Zone
LaPremiereDispo = Sheets(Zone).Range("E65536").End(xlUp).Offset(1, 0).Row
MsgBox "the first cell for this month is" & LaPremiereDispo
End Sub



  #3   Report Post  
Rowan
 
Posts: n/a
Default

You will get this error if you do not have a sheet with a name that matches
the variable zone. Also you do not need the loop. Try it like this:

Private Sub Cmd_Valid_Click()
Dim sht As Worksheet
Dim LaPremiereDispo As Long
Dim zone As String
If Range("R28").Value = 1 And Range("R28").Value <= 12 Then
zone = "Feuil" & Range("R28").Value + 4
MsgBox "Selected sheet is " & zone
On Error Resume Next
Set sht = Sheets(zone)
On Error GoTo 0
If sht Is Nothing Then
MsgBox "Sheet does not exist"
Else
LaPremiereDispo = sht.Range("E65536").End(xlUp).Offset(1, 0).Row
MsgBox "the first cell for this month is " & LaPremiereDispo
End If
End If
End Sub

Hope this helps
Rowan

"christophe meresse" wrote:



Hi !

I'm trying this code but I have a code error 9
Can you help me ?


Private Sub Cmd_Valid_Click()
Dim c As Integer
c = 1
For c = 1 To 12
If Range("R28").Value = c Then
Zone = "Feuil" & c + 4
End If
Next c
MsgBox "Selected sheet is" & Zone
LaPremiereDispo = Sheets(Zone).Range("E65536").End(xlUp).Offset(1, 0).Row
MsgBox "the first cell for this month is" & LaPremiereDispo
End Sub




  #4   Report Post  
christophe meresse
 
Posts: n/a
Default


Oki doki, I see my problem now,

Thank you for your help


"Rowan" a écrit dans le message de
...
You will get this error if you do not have a sheet with a name that

matches
the variable zone. Also you do not need the loop. Try it like this:

Private Sub Cmd_Valid_Click()
Dim sht As Worksheet
Dim LaPremiereDispo As Long
Dim zone As String
If Range("R28").Value = 1 And Range("R28").Value <= 12 Then
zone = "Feuil" & Range("R28").Value + 4
MsgBox "Selected sheet is " & zone
On Error Resume Next
Set sht = Sheets(zone)
On Error GoTo 0
If sht Is Nothing Then
MsgBox "Sheet does not exist"
Else
LaPremiereDispo = sht.Range("E65536").End(xlUp).Offset(1, 0).Row
MsgBox "the first cell for this month is " & LaPremiereDispo
End If
End If
End Sub

Hope this helps
Rowan

"christophe meresse" wrote:



Hi !

I'm trying this code but I have a code error 9
Can you help me ?


Private Sub Cmd_Valid_Click()
Dim c As Integer
c = 1
For c = 1 To 12
If Range("R28").Value = c Then
Zone = "Feuil" & c + 4
End If
Next c
MsgBox "Selected sheet is" & Zone
LaPremiereDispo = Sheets(Zone).Range("E65536").End(xlUp).Offset(1,

0).Row
MsgBox "the first cell for this month is" & LaPremiereDispo
End Sub








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
Change case...help please Terry Excel Worksheet Functions 14 October 2nd 05 12:29 PM
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM


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