lucpian
04-09-2008, 07:34 PM
Hi All,
I am having problem with a code I wrote that was working. The problem is that the template that contains this code will be used for both un-orderly and orderly headings with the headings placed at various position on the sheet. My code was to validate various length and it works perfectly with orderly headings, but not with un-orderly headings. Here is my code:
Function CheckLength(columnname As Integer, length As Integer)
Dim rowcount
Dim R
rowcount = Range("A65536").End(xlUp).Row
For R = 2 To rowcount
strVal = LTrim(RTrim(Sheet1.Cells(R, columnname).Value))
'MsgBox Len(strVal)
Sheet1.Cells(R, columnname).Value = strVal
If strVal <> "" And (Not (Len(strVal) = length)) Then
Sheet1.Cells(R, columnname).Interior.ColorIndex = 6
End If
Next
End Function
Sub LengthValidation()
CheckLength 1, 13
CheckLength 8, 4
End Sub
Please, I need help because I keep having errors when this un-orderly data are imported into the template.
Thanks all for all your help.
Lucpian
I am having problem with a code I wrote that was working. The problem is that the template that contains this code will be used for both un-orderly and orderly headings with the headings placed at various position on the sheet. My code was to validate various length and it works perfectly with orderly headings, but not with un-orderly headings. Here is my code:
Function CheckLength(columnname As Integer, length As Integer)
Dim rowcount
Dim R
rowcount = Range("A65536").End(xlUp).Row
For R = 2 To rowcount
strVal = LTrim(RTrim(Sheet1.Cells(R, columnname).Value))
'MsgBox Len(strVal)
Sheet1.Cells(R, columnname).Value = strVal
If strVal <> "" And (Not (Len(strVal) = length)) Then
Sheet1.Cells(R, columnname).Interior.ColorIndex = 6
End If
Next
End Function
Sub LengthValidation()
CheckLength 1, 13
CheckLength 8, 4
End Sub
Please, I need help because I keep having errors when this un-orderly data are imported into the template.
Thanks all for all your help.
Lucpian