Im new to VBA, so I will geve you some context and purpose of what I hope to achieve. I am copying data from another program (no issues), I then paste it into a WorkSheet that I have coded the formate for the incoming data to nest where I want it to be (looks pretty), I paste by using a UserForm I created (still no issues). I then created another UserForm and use this to sort the data for number of days between date ranges (used VBA with formula) and if no date is present then I assign todays date (Date) all the above works great. My issue is when the user has completed the above, another UserForm pops up to ask if they want to add the overdue data to the report sheet, this is supposed to copy any rows that have todays date (Date) in Column "G" and then paste it to the report sheet row "A1" down
I would appreciate the help, I have tried a few options and searched high and wide on the net, with the following code so far it looks down column 7, currently I have 15 row items to sort through and two of them have todays date. I keep only getting the last of the two required rows with todays date to paste into the report sheet from the data sheet?
Here is the full code so far with your additional code (the first part formates the destination sheet and as you can see it ensures that destination sheet column "G" is set to format "dd/mm/yyyy":
Private Sub CommandButton1_Click()
Me.Hide
If Sheets("Masri").Visible Then
Sheet10.Activate
Sheet10.Cells.Clear
Sheet10.Cells.ClearFormats
Range("A1:I2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark2
.TintAndShade = -0.499984740745262
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.Font.Bold = True
Range("A1:I2").Select
ActiveCell.FormulaR1C1 = _
"Number of Days between ANSI's Aproved But not Catalogued"
Range("A3:I3").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark2
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
Range("A3:I3").Select
ActiveCell.FormulaR1C1 = "MASRI"
Range("A4").Select
ActiveCell.FormulaR1C1 = "Progress"
Selection.Font.Bold = True
Range("B4").Select
ActiveCell.FormulaR1C1 = "ANSI#"
Selection.Font.Bold = True
Range("C4").Select
ActiveCell.FormulaR1C1 = "Area"
Selection.Font.Bold = True
Range("D4").Select
ActiveCell.FormulaR1C1 = "Supplier"
Selection.Font.Bold = True
Range("E4").Select
ActiveCell.FormulaR1C1 = "Description"
Selection.Font.Bold = True
Range("F4").Select
ActiveCell.FormulaR1C1 = "Approved Date"
Selection.Font.Bold = True
Range("G4").Select
ActiveCell.FormulaR1C1 = "Catalogued Date"
Selection.Font.Bold = True
Range("H4").Select
ActiveCell.FormulaR1C1 = "Approved By"
Selection.Font.Bold = True
Range("I4").Select
ActiveCell.FormulaR1C1 = "Days Overdue"
Selection.Font.Bold = True
Range("A4:I4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A4:I4").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
Range("A1:I4").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("G5:G40").NumberFormat = "dd/mm/yyyy"
Columns("A:A").ColumnWidth = 18.43
Columns("B:B").ColumnWidth = 12
Columns("C:C").ColumnWidth = 4.43
Columns("D:D").ColumnWidth = 34.86
Columns("E:E").ColumnWidth = 60.71
Columns("F:F").ColumnWidth = 15.14
Columns("G:G").ColumnWidth = 15.14
Columns("H:H").ColumnWidth = 20.57
Columns("I:I").ColumnWidth = 37.86
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 1")).Select
Range("A1:I2").Select
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 1")).Select
Selection.ShapeRange.IncrementLeft -2.25
Selection.ShapeRange.IncrementTop 0.75
Selection.ShapeRange.IncrementLeft 2.25
Selection.ShapeRange.IncrementTop -0.75
Sheets("Masri").Select
Dim FinalRow As Long, lastTargetRow As Long, lastCol As Long, tRow As Long
Dim source As String, target As String
Dim ThisValue As Date
source = "Masri" 'Define your source sheet
target = "Reports" 'Define Target sheet
FinalRow = Sheets(source).Range("G" & Rows.Count).End(xlUp).Row
lastCol = Sheets(source).Cells(1, Columns.Count).End(xlToLeft).Column 'If header in Row 1
lastTargetRow = Sheets(target).Range("G" & Rows.Count).End(xlUp).Row
tRow = lastTargetRow + 1
For lRow = 2 To FinalRow
ThisValue = Sheets(source).Cells(lRow, 7).Value
If ThisValue = tempDate Then
For lCol = 1 To lastCol 'Copy entire row
Sheets(target).Cells(tRow, lCol).Value = Sheets(source).Cells(lRow, lCol).Value
Next lCol
tRow = tRow + 1 'THIS IS THE KEY TO NOT JUST COPYING THE LAST RECORD
End If
Next lRow
End If
End Sub