Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default val() is not work in my code

wrote the below code and i'm haveing problems when i get to:
"
StrAStart = CInt(Val(Left(SltArea, StrM)))
StrAEnd = CInt(Val(Right(SltArea, strL - StrM)))
"
part of my code, it looks like it is when i get to Val. When the program
gets to these lines it doesn't put anything for variables StrAStart and
StrAEnd. Varaible SltArea will contain something like "$A$35:$J$43". I am
trying to get the starting, and ending row that was pasted by program. If you
know a way to fix my code to make this work or even a better way to get the
info i need, it would be greatly appreciated.

Private Sub CBAddPending_Click()
Dim PendingSheet As Variant
Set PendingSheet = Worksheets("Pending List")

Dim StartRows As Integer
StartRows = 6

Dim MaxNoRows As Integer
MaxNoRows = 400

Dim CountRow As Integer
CountRow = StartRows

Dim SltArea As String
Dim StrM As Integer
Dim strL As Integer
Dim StrAStart As Integer
Dim StrAEnd As Integer



Do While CountRow < MaxNoRows
If PendingSheet.Range("A" & CountRow) = "" Then

If PendingSheet.Range("a" & CountRow + 1) = 1 Then
CountRow = CountRow + 1
Else
Exit Do
End If

Else
CountRow = CountRow + 1
End If
Loop

PendingSheet.Range("A" & CountRow) = DaySelected
CountRow = CountRow + 1
PendingSheet.Range("A" & CountRow).PasteSpecial

SltArea = (Selection.Address)
StrM = InStr(SltArea, ":")
strL = Len(SltArea)
StrAStart = CInt(Val(Left(SltArea, StrM)))
StrAEnd = CInt(Val(Right(SltArea, strL - StrM)))

Range("A" & StrAStart, "B" & StrAEnd).Delete

Range("A" & StrAStart, "A" & StrAEnd).Cells.NumberFormat = "Number"

CountRow = StrAStart
Do While CountRow StrAEnd
If Len(PendingSheet.Range("A" & CountRow)) = 12 Then
If Left(PendingSheet.Range("A" & CountRow), 2) = 65 Then
PendingSheet.Range("A" & CountRow) = "'0" &
PendingSheet.Range("A" & CountRow)
Else

End If
Else

End If

CountRow = CountRow + 1
Loop



End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default val() is not work in my code

Try this:

Dim strRng As String
strRng = Split(SltArea,":",2)
StrAStart = strRng(0)
StrAEnd = strRng(1)

Instead of

StrM = InStr(SltArea, ":")
strL = Len(SltArea)
StrAStart = CInt(Val(Left(SltArea, StrM)))
StrAEnd = CInt(Val(Right(SltArea, strL - StrM)))



"Mr. GetRight" wrote in message
...
wrote the below code and i'm haveing problems when i get to:
"
StrAStart = CInt(Val(Left(SltArea, StrM)))
StrAEnd = CInt(Val(Right(SltArea, strL - StrM)))
"
part of my code, it looks like it is when i get to Val. When the program
gets to these lines it doesn't put anything for variables StrAStart and
StrAEnd. Varaible SltArea will contain something like "$A$35:$J$43". I am
trying to get the starting, and ending row that was pasted by program. If
you
know a way to fix my code to make this work or even a better way to get
the
info i need, it would be greatly appreciated.

Private Sub CBAddPending_Click()
Dim PendingSheet As Variant
Set PendingSheet = Worksheets("Pending List")

Dim StartRows As Integer
StartRows = 6

Dim MaxNoRows As Integer
MaxNoRows = 400

Dim CountRow As Integer
CountRow = StartRows

Dim SltArea As String
Dim StrM As Integer
Dim strL As Integer
Dim StrAStart As Integer
Dim StrAEnd As Integer



Do While CountRow < MaxNoRows
If PendingSheet.Range("A" & CountRow) = "" Then

If PendingSheet.Range("a" & CountRow + 1) = 1 Then
CountRow = CountRow + 1
Else
Exit Do
End If

Else
CountRow = CountRow + 1
End If
Loop

PendingSheet.Range("A" & CountRow) = DaySelected
CountRow = CountRow + 1
PendingSheet.Range("A" & CountRow).PasteSpecial

SltArea = (Selection.Address)
StrM = InStr(SltArea, ":")
strL = Len(SltArea)
StrAStart = CInt(Val(Left(SltArea, StrM)))
StrAEnd = CInt(Val(Right(SltArea, strL - StrM)))

Range("A" & StrAStart, "B" & StrAEnd).Delete

Range("A" & StrAStart, "A" & StrAEnd).Cells.NumberFormat = "Number"

CountRow = StrAStart
Do While CountRow StrAEnd
If Len(PendingSheet.Range("A" & CountRow)) = 12 Then
If Left(PendingSheet.Range("A" & CountRow), 2) = 65 Then
PendingSheet.Range("A" & CountRow) = "'0" &
PendingSheet.Range("A" & CountRow)
Else

End If
Else

End If

CountRow = CountRow + 1
Loop



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
Verify Canadian Postal Code ~ make the code work jat Excel Programming 2 February 27th 09 09:12 PM
VBA code does not work Frank Situmorang[_2_] Excel Programming 7 November 6th 08 05:00 AM
Code just won't work... Gordon[_2_] Excel Programming 0 July 31st 06 03:32 PM
Code Does Not Work Minitman[_4_] Excel Programming 21 December 16th 04 09:30 PM
Help getting code to work. Frank Stone Excel Programming 1 July 28th 04 10:01 PM


All times are GMT +1. The time now is 01:57 AM.

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"