I have a spread sheet that I need to run some data validations for. I am checking to see if a particular column is blank or not. First tried using countA for the column but it always returns a 1 even if I add several rows of data. then switch to counting rows and trying to iterate through checking certain fields to see if they have data. Nothing seems to work.
Code:
Public Sub MissingDataChk()
'Created by: Steve E'
'Create Date: 5/12/11
'Comments: This prcedure performs the following:
'1. Validates that required data is not missing
'______________________________________________________________________
Dim cC$
Dim vr As Variant
Dim vri As Variant
Dim i%, lastrow#
Dim xls As Worksheet
'initializes variables
Range("B1:b65536").Select ' for testing
MDF = False
lastrow# = 0 'initialize
lastrow# = Worksheets(1).Range("B1:B65536").Find("*", LookIn:=xlValues).Column 'method 1 not working returns a 2
lastrow# = Cells.Find("*", SearchOrder:=xlByRows, Searchdirection:=xlPrevious).Column 'method 2 not working returns 34
lastrow# = Application.WorksheetFunction.CountA("B:B") 'method 3 not working returns a
lastrow# = WorksheetFunction.CountA("B1:B65536") 'method 4 not working returns a 1
MsgBox lastrow
i = 1
vr = Array("A" & i + 1, "B" & i + 1, "C" & i + 1, "E" & i + 1, "F" & i + 1, "P" & i + 1, "R" & i + 1, "U" & i + 1)
'Perform the check by row
Do While i <= lastrow
For Each vri In vr
If Range(vri).Value = "" Then
MsgBox "Required Data is Missing in " & vri & "." & vbCrLf & _
"Check all columns with Red headings." & vbCrLf & vbCrLf & _
"Note: If a column heading is red, it is required." & vbCrLf & vbCrLf & _
"Correct issue then try again.", vbCritical, "MISSING REQUIRED DATA"
Range(vri).Select
MDF = True
Exit For
End If
Next
i = i + 1
Loop
'Clean Up
cC$ = Empty
Set vr = Nothing
Set vri = Nothing
i% = Empty
lastrow# = Empty
Set xls = Nothing
End Sub
Column B of spread sheet has a header and in rows 2 - 7 has alphanumeric data.
S J E
If I am not learning, then I am coasting, if I am coasting I must be going down hill.
Code:
Public Sub MissingDataChk()
'Created by: Steve E'
'Create Date: 5/12/11
'Comments: This prcedure performs the following:
'1. Validates that required data is not missing
'______________________________________________________________________
Dim cC$
Dim vr As Variant
Dim vri As Variant
Dim i%, lastrow#
Dim xls As Worksheet
'initializes variables
Range("B1:b65536").Select ' for testing
MDF = False
lastrow# = 0 'initialize
lastrow# = Worksheets(1).Range("B1:B65536").Find("*", LookIn:=xlValues).Column 'method 1 not working returns a 2
lastrow# = Cells.Find("*", SearchOrder:=xlByRows, Searchdirection:=xlPrevious).Column 'method 2 not working returns 34
lastrow# = Application.WorksheetFunction.CountA("B:B") 'method 3 not working returns a
lastrow# = WorksheetFunction.CountA("B1:B65536") 'method 4 not working returns a 1
MsgBox lastrow
i = 1
vr = Array("A" & i + 1, "B" & i + 1, "C" & i + 1, "E" & i + 1, "F" & i + 1, "P" & i + 1, "R" & i + 1, "U" & i + 1)
'Perform the check by row
Do While i <= lastrow
For Each vri In vr
If Range(vri).Value = "" Then
MsgBox "Required Data is Missing in " & vri & "." & vbCrLf & _
"Check all columns with Red headings." & vbCrLf & vbCrLf & _
"Note: If a column heading is red, it is required." & vbCrLf & vbCrLf & _
"Correct issue then try again.", vbCritical, "MISSING REQUIRED DATA"
Range(vri).Select
MDF = True
Exit For
End If
Next
i = i + 1
Loop
'Clean Up
cC$ = Empty
Set vr = Nothing
Set vri = Nothing
i% = Empty
lastrow# = Empty
Set xls = Nothing
End Sub
Column B of spread sheet has a header and in rows 2 - 7 has alphanumeric data.
S J E
If I am not learning, then I am coasting, if I am coasting I must be going down hill.