Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
The msgbox in the "strip" function below has a good value.
But when I check it in the " MsgBox "after strip comp1=" & comp1 & ", comp2=" & comp2 " box, there is no value. Any help would be greatly appreciated. Sam Sub compare_output() Dim str1 As String Dim str2 As String Dim comp1 As String Dim comp2 As String r = 1 Dim lastrow As Long, i As Long ActiveSheet.UsedRange With Cells.SpecialCells(xlCellTypeLastCell) lastrow = .Row End With For i = 1 To lastrow str1 = ActiveSheet.Cells(r, 1) str2 = ActiveSheet.Cells(r, 2) MsgBox "str1=" & str1 & ", str2=" & str2 comp1 = strip(str1) comp2 = strip(str2) MsgBox "after strip comp1=" & comp1 & ", comp2=" & comp2 If (comp1 < comp2) Then XColor = 5 Else XColor = 7 End If If (XColor) Then Range(ActiveSheet.Cells(r, 1), ActiveSheet.Cells(r, 2)).Select With Selection.Interior .ColorIndex = XColor .Pattern = xlSolid End With End If r = r + 1 Next End Sub Function strip(chars) Dim buff As String buff = " " For i = 1 To Len(chars) If Mid(chars, i, 1) " " Then buff = buff & Mid(chars, i, 1) End If Next i MsgBox "buff=" & buff End Function |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Strip is never set in the function of the same name.
-- Gary''s Student "Nooby" wrote: The msgbox in the "strip" function below has a good value. But when I check it in the " MsgBox "after strip comp1=" & comp1 & ", comp2=" & comp2 " box, there is no value. Any help would be greatly appreciated. Sam Sub compare_output() Dim str1 As String Dim str2 As String Dim comp1 As String Dim comp2 As String r = 1 Dim lastrow As Long, i As Long ActiveSheet.UsedRange With Cells.SpecialCells(xlCellTypeLastCell) lastrow = .Row End With For i = 1 To lastrow str1 = ActiveSheet.Cells(r, 1) str2 = ActiveSheet.Cells(r, 2) MsgBox "str1=" & str1 & ", str2=" & str2 comp1 = strip(str1) comp2 = strip(str2) MsgBox "after strip comp1=" & comp1 & ", comp2=" & comp2 If (comp1 < comp2) Then XColor = 5 Else XColor = 7 End If If (XColor) Then Range(ActiveSheet.Cells(r, 1), ActiveSheet.Cells(r, 2)).Select With Selection.Interior .ColorIndex = XColor .Pattern = xlSolid End With End If r = r + 1 Next End Sub Function strip(chars) Dim buff As String buff = " " For i = 1 To Len(chars) If Mid(chars, i, 1) " " Then buff = buff & Mid(chars, i, 1) End If Next i MsgBox "buff=" & buff End Function |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Sorry, but I am new to this and I'm working as a fill in on a real
project. I don't understand your answer. How do I set it? |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Function strip(chars)
Dim buff As String buff = " " For i = 1 To Len(chars) If Mid(chars, i, 1) " " Then buff = buff & Mid(chars, i, 1) End If Next i MsgBox "buff=" & buff strip=buff End Function Note the added last statement before the End Function -- Gary''s Student "Nooby" wrote: Sorry, but I am new to this and I'm working as a fill in on a real project. I don't understand your answer. How do I set it? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Custom functions calculating time arguments Help Desperate | Excel Worksheet Functions | |||
VLookUp function to return multiple rows | Excel Worksheet Functions | |||
Can a function return a Null (blank ) value? Maybe a custom functi | Excel Worksheet Functions | |||
Function to check list for specific conditions and return an answe | Excel Discussion (Misc queries) | |||
Error Return Value from and INDEX(A:2,MATCH()) function | Excel Worksheet Functions |