motabrasil
New Member
- Joined
- May 11, 2010
- Messages
- 28
Dear Sirs,
I need to create a code to capture information from a DATABASE.file (closed Workbook) and Sum or Count, based on a several criterias, in the Dashboard.file (Active Workbook). See described below the initial Code.
How to count the numbers of non blanks rows from the DATABASE.file
column "C" for instance (see in the code highlighted in RED)?
When I run this code, it's capturing the last row from the active workbook.
Sub CaptureInfo()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
Dim Results(0 To 1) As Long<o
></o
>
Dim LastRow As Long<o
></o
>
Dim I As Integer<o
></o
>
Dim FilePath$<o
></o
>
<o
></o
>
<o
></o
>
Const Filename$ = "DataBase.xls"<o
></o
>
Const SheetName$ = "Sheet1"<o
></o
>
FilePath = ActiveWorkbook.Path & "\"<o
></o
>
<o
></o
>
DoEvents<o
></o
>
Application.ScreenUpdating = False<o
></o
>
If Dir(FilePath & Filename) = Empty Then<o
></o
>
MsgBox "The file " & Filename & " was not found", , "File Doesn't Exist"<o
></o
>
Exit Sub<o
></o
>
End If<o
></o
>
<o
></o
>
Application.Calculation = xlManual<o
></o
>
<o
></o
>
LastRow = 1<o
></o
>
<o
></o
>
Do While Cells(LastRow, "C") <> ""<o
></o
>
LastRow = LastRow + 1<o
></o
>
Loop<o
></o
>
<o
></o
>
LastRow = LastRow - 1<o
></o
>
<o
></o
>
For I = 1 To LastRow<o
></o
>
If Cells(I, "F").Value < 0 Then<o
></o
>
If UCase(Cells(I, "AP").Value = "Vendor1") Then<o
></o
>
Cells(I, "F").Value = Cells(I, "F").Value<o
></o
>
Results(0) = Results(0) + Cells(I, "F").Value<o
></o
>
End If<o
></o
>
End If<o
></o
>
If Cells(I, "F").Value < 0 Then<o
></o
>
If UCase(Cells(I, "AP").Value = "Vendor2") Then<o
></o
>
Cells(I, "F").Value = Cells(I, "F").Value<o
></o
>
Results(1) = Results(1) + Cells(I, "F").Value<o
></o
>
End If<o
></o
>
End If<o
></o
>
<o
></o
>
Next I<o
></o
>
<o
></o
>
Sheets("Dashboard").Select<o
></o
>
<o
></o
>
Range("E6") = Results(0)<o
></o
>
Range("E7") = Results(1)<o
></o
>
<o
></o
>
<o
></o
>
Application.Calculation = xlAutomatic<o
></o
>
Application.ScreenUpdating = True<o
></o
>
<o
></o
>
MsgBox "Done!!!"<o
></o
>
<o
></o
>
End Sub
Thanks in advance
Mota
I need to create a code to capture information from a DATABASE.file (closed Workbook) and Sum or Count, based on a several criterias, in the Dashboard.file (Active Workbook). See described below the initial Code.
How to count the numbers of non blanks rows from the DATABASE.file
column "C" for instance (see in the code highlighted in RED)?
When I run this code, it's capturing the last row from the active workbook.
Sub CaptureInfo()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com




Dim Results(0 To 1) As Long<o


Dim LastRow As Long<o


Dim I As Integer<o


Dim FilePath$<o


<o


<o


Const Filename$ = "DataBase.xls"<o


Const SheetName$ = "Sheet1"<o


FilePath = ActiveWorkbook.Path & "\"<o


<o


DoEvents<o


Application.ScreenUpdating = False<o


If Dir(FilePath & Filename) = Empty Then<o


MsgBox "The file " & Filename & " was not found", , "File Doesn't Exist"<o


Exit Sub<o


End If<o


<o


Application.Calculation = xlManual<o


<o


LastRow = 1<o


<o


Do While Cells(LastRow, "C") <> ""<o


LastRow = LastRow + 1<o


Loop<o


<o


LastRow = LastRow - 1<o


<o


For I = 1 To LastRow<o


If Cells(I, "F").Value < 0 Then<o


If UCase(Cells(I, "AP").Value = "Vendor1") Then<o


Cells(I, "F").Value = Cells(I, "F").Value<o


Results(0) = Results(0) + Cells(I, "F").Value<o


End If<o


End If<o


If Cells(I, "F").Value < 0 Then<o


If UCase(Cells(I, "AP").Value = "Vendor2") Then<o


Cells(I, "F").Value = Cells(I, "F").Value<o


Results(1) = Results(1) + Cells(I, "F").Value<o


End If<o


End If<o


<o


Next I<o


<o


Sheets("Dashboard").Select<o


<o


Range("E6") = Results(0)<o


Range("E7") = Results(1)<o


<o


<o


Application.Calculation = xlAutomatic<o


Application.ScreenUpdating = True<o


<o


MsgBox "Done!!!"<o


<o


End Sub
Thanks in advance
Mota