Hi there, yes I know it's in there, I just can't seem to figure out how to pull it out...
warning: it's quite long!
Sub RollUp()
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim wsDestBU As Worksheet 'BU back-up
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim iIdx As Integer
Dim sAuditNum As String
Dim sMessage As String
Dim lIdx As Long
Dim lBUCount As Long
Dim lCopyCount As Long
'''I've cut out the code that finds and sets the Source and Dest ws/wb'''
lCopyCount = 0: lBUCount = 0
sAuditNum = wbSource.Sheets("Quality Review Input Sheet").Range("C5").Value & "" 'set string version (could have letters) and in excel it guesses the formating/format to text or numeric, so we will set our formatting ourselves
'take the value(c5) and concantenate the value(number/letter) will make sure it sets it as a string for sure!! makes sure we are looking for text versions of those characters
' calculate movement quantities and prompt for confirm before actually doing anything - it will calc # of things it will move from DestSheet to DestBU and calc # of rows in "N" with a 1. askes us to verify what we are moving over.
' count destination records to move
For lIdx = wsDest.Cells(25000, 1).End(xlUp).Row To 2 Step -1 'row2 is beginnig of data, row 1 is header.
If (wsDest.Cells(lIdx, 1).Value & "" = sAuditNum & "") Then lBUCount = lBUCount + 1
Next lIdx '&"" to be sure its a text and balance it out on sAduit to be sure they are both text.
' count rows in Source that have value of 1 in column N (column 14)
For lIdx = wsSource.Cells(500, 1).End(xlUp).Row To 2 Step -1
If Not (IsError(wsSource.Cells(lIdx, 14).Value)) Then
If (wsSource.Cells(lIdx, 14).Value = 1) Then lCopyCount = lCopyCount + 1
End If
Next lIdx
If lBUCount >= 1 Then
sMessage = "Audit Number : " & sAuditNum & vbCr & vbCr & _
"Note: " & lBUCount & " existing records were found. They will be moved to the Back Up tab." & vbCr & _
lCopyCount & " records will be copied" & _
vbCr & vbCr & "Continue?"
' exit if user selected NO, otherwise continue
If MsgBox(sMessage, vbQuestion + vbYesNo, "") = vbNo Then Exit Sub
End If
lCopyCount = 0: lBUCount = 0
' move any records in the destination matching the AuditNumber to the followup archive
For lIdx = wsDest.Cells(25000, 1).End(xlUp).Row To 2 Step -1
If (wsDest.Cells(lIdx, 1).Value & "" = sAuditNum & "") Then
wsDest.Cells(lIdx, 1).EntireRow.Cut wsDestBU.Cells(wsDestBU.Cells(25000, 1).End(xlUp).Row + 1, 1)
wsDest.Cells(lIdx, 1).EntireRow.Delete Shift:=xlUp
lBUCount = lBUCount + 1
End If
Next lIdx
' copy rows in Source that have value of 1 in column N (column 14)
For lIdx = wsSource.Cells(500, 1).End(xlUp).Row To 2 Step -1
If Not (IsError(wsSource.Cells(lIdx, 14).Value)) Then
If (wsSource.Cells(lIdx, 14).Value = 1) Then
wsSource.Cells(lIdx, 1).EntireRow.Copy
wsDest.Cells(wsDest.Cells(25000, 1).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
lCopyCount = lCopyCount + 1 'tally to check when I do a copy to test to see how much stuff was moved, used for later
End If
End If
Next lIdx
' error message if no transfers
If lCopyCount = 0 Then
MsgBox "There was no data to copy. Check column N " & vbCr & _
"to make sure there are scores.", vbExclamation, "No Data Copied"
Exit Sub
End If
CleanUp:
Set wsSource = Nothing: Set wbSource = Nothing ': means you have 2 lines of code on one row
Set wsDest = Nothing: Set wbDest = Nothing
Set wsDestBU = Nothing
End Sub
I am already counting the rows, and the data stays together when it is copied... but I wanted to know where on the ws.Source tab the data was coming from before it's being copied to the Archive tab. I was going to populate the row addresses (i.e. Rows(3:15)) in a column on the Archive tab, I was thinking in the first row of data for each audit #.
Any advise/direction would be greatly appreciated!
Bookmarks