Public Sub SummarizeMetriguard()
Dim NumOfRows As Integer
Dim GetMaxRows As Integer
Dim cFind As Range
Dim cFind1 As Range
Dim cAllocate As String
Dim cAllocate1 As String
Dim bFound As Boolean
Dim r As Long
Sheets("DownloadSheet").Select
sqlString = "SELECT datapcno, datauptus, dataucupt, datauptrdgs, dataavguptsig, dataavguptsn, dataskew, datamc, datamcmax, datasg, datarfscans, dataegpa, dataerdgs, datatempc, datawidthcm, datathickmm, datasg1, datasg2, datasg3,datadatfile, datasaptype, dataforestry FROM tbldata WHERE datareported='N' and datadatfile = (select min(datadatfile) from tbldata where datareported='N')"
connString = "ODBC;DSN=REPORTSYSDB"
With ActiveWorkbook.Sheets("DownloadSheet").QueryTables.Add(Connection:=connString, _
Destination:=Range("A6"), Sql:=sqlString)
.Refresh
End With
Sheets("DownloadSheet").Select
GetMaxRows = ActiveWorkbook.Sheets("DownloadSheet").Range("A65536").End(xlUp).Row
NumOfRows = GetMaxRows
If NumOfRows > 6 Then
Sheets("DownloadSheet").Range("W6:AM6").Copy
Sheets("DownloadSheet").Range("W7:AM" & NumOfRows).PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False
End If
Sheets("DownloadSheet").Range("T7").Copy
Sheets("SummarySheet").Select
Sheets("SummarySheet").Range("A24").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Sheets("SummarySheet").Rows("24:24").Copy
Sheets("Report").Select
Sheets("Report").Range("A3").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Sheets("DownloadSheet").Select
Set cFind = Sheets("DownloadSheet").Range("V7")
cAllocate = cFind
Sheets("DownloadSheet").Select
Set cFind1 = Sheets("DownloadSheet").Range("U7")
cAllocate1 = cFind1
Sheets("ForestStiffnessSummary").Select
r = 0
While Not bFound And r < 65536
r = r + 1
If Sheets("ForestStiffnessSummary").Range("A" & r).Value = cAllocate Then
bFound = True
End If
Wend
bFound = False
While Not bFound And r < 65536
r = r + 1
If Sheets("ForestStiffnessSummary").Range("A" & r).Value = cAllocate1 Then
bFound = True
End If
Wend
bFound = False
While Not bFound And r < 65536
r = r + 1
If Sheets("ForestStiffnessSummary").Range("A" & r).Value = "" Then
bFound = True
Sheets("Report").Select
Sheets("Report").Rows("3:3").Copy
Sheets("ForestStiffnessSummary").Select
Sheets("ForestStiffnessSummary").Range("A" & r).PasteSpecial Paste:=xlPasteValues
ActiveCell.Offset(1).EntireRow.Insert
Application.CutCopyMode = False
End If
Wend
With ActiveWorkbook.Sheets("DownloadSheet")
.Range("A6:V65536").ClearContents
.Range("W7:AM65536").ClearContents
End With
With ActiveWorkbook.Sheets("SummarySheet")
.Range("A24").ClearContents
End With
With ActiveWorkbook.Sheets("Report")
.Range("A3:T3").ClearContents
End With
Sheets("ForestStiffnessSummary").Select
End Sub