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: 117
Default Just can't get the LEN/MID thing quite right...

Hi guys and gals

The code below looks down a column of numbers, the column can
have 2, 3 or 4 digits in each cell... the macro it is supposed to look
at the amount of digits in each cell and execute from there...

It works fine if the cell has 4 digits... but not if the cell has 2 or
3 digits!
I must have something wrong with the LEN and MID bit, can anyone see
the error?

As an example if a cell has 619 entered...when the code breaks, in
debug
mode, two1 holds 61 and two2 holds 9 whereas it should be 6 and 19...
same with 2 digits...
I have been struggling with this a bit...cheers

ste

Sub condata()
Application.ScreenUpdating = False
Sheets("The data").Select
Dim xlrow As Long
Dim two1 As Integer
Dim two2 As Integer
Dim two1prob
Dim two2prob
xlrow = 3
ActiveSheet.Range("J3").Select
Do While Not (ActiveSheet.Cells(xlrow, 10).Value = "")


If Len(ActiveSheet.Cells(xlrow, 10).Value = 2) Then
two1 = Left(ActiveSheet.Cells(xlrow, 10).Value, 1)
two2 = Mid(ActiveSheet.Cells(xlrow, 10).Value, 2, 1)
End If

If Len(ActiveSheet.Cells(xlrow, 10).Value = 3) Then
two1 = Left(ActiveSheet.Cells(xlrow, 10).Value, 1)
two2 = Mid(ActiveSheet.Cells(xlrow, 10).Value, 2, 2)
End If

If Len(ActiveSheet.Cells(xlrow, 10).Value = 4) Then
two1 = Left(ActiveSheet.Cells(xlrow, 10).Value, 2)
two2 = Mid(ActiveSheet.Cells(xlrow, 10).Value, 3, 2)
End If

ActiveSheet.Range("V3:V51").Select
Selection.Find(What:=two1, After:=ActiveCell, LookIn:=xlValues,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Select
two1prob = ActiveCell.Value

ActiveSheet.Range("V3:V51").Select
Selection.Find(What:=two2, After:=ActiveCell, LookIn:=xlValues,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Select
two2prob = ActiveCell.Value

ActiveSheet.Cells(xlrow, 12).Value = two1prob * two2prob
xlrow = xlrow + 1

Loop

End Sub

 
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
One Last Thing Coltsfan Excel Discussion (Misc queries) 1 January 16th 06 08:42 PM
For/Next using Thing Lindy[_2_] Excel Programming 3 December 3rd 04 07:18 PM
Doing it's own thing André Excel Programming 3 July 9th 04 11:30 PM
oh, and another thing ted daniels Excel Programming 2 April 22nd 04 05:34 PM
New to this thing BowD Excel Programming 2 December 19th 03 03:29 AM


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