Hi All!
I have quite of bit of data on one worksheet and the way it is structured works great. What I am trying to do now is take some of that data that has a number >= 1 in cells A22:A115 and copy A22:B115 and J22:J115 to Sheet2 starting in A15. Any row without a number in A22:A115 would not be copied.
Once the data is copied to Sheet2, I want to print to PDF and save it to the desktop - this part I think I have figured out - sort of.
Here is the code I have now, but can't figure out how to get it to work the way I need it to:
When I run the code, it only copies the last row with a number >=1 in column A of Sheet1 to Sheet2, instead of all of the rows that have a number >=1 in column A.
If I can get the above code to work, is there a way to integrate the below code to print the data to PDF, so when the code above is executed, it will copy/paste the data, then print to PDF 'Sheet2' all at once?
I really appreciate any help I can get with this!
I have quite of bit of data on one worksheet and the way it is structured works great. What I am trying to do now is take some of that data that has a number >= 1 in cells A22:A115 and copy A22:B115 and J22:J115 to Sheet2 starting in A15. Any row without a number in A22:A115 would not be copied.
Once the data is copied to Sheet2, I want to print to PDF and save it to the desktop - this part I think I have figured out - sort of.
Here is the code I have now, but can't figure out how to get it to work the way I need it to:
VBA Code:
Sub CopyCells()
Dim i As Integer
Dim Lastrow As Long
'Declaring variables
Dim rng As Range
Set rng = Range("A22:B115, J22:J115" & Lastrow)
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
If Cells(i, 1).Value >= 1 Then
Sheets("Sheet2").Cells(15, 1).Value = Sheets("Sheet1").Cells(i, 1).Value
Sheets("Sheet2").Cells(15, 2).Value = Sheets("Sheet1").Cells(i, 2).Value
Sheets("Sheet2").Cells(15, 3).Value = Sheets("Sheet1").Cells(i, 10).Value
End If
Next
End Sub
When I run the code, it only copies the last row with a number >=1 in column A of Sheet1 to Sheet2, instead of all of the rows that have a number >=1 in column A.
If I can get the above code to work, is there a way to integrate the below code to print the data to PDF, so when the code above is executed, it will copy/paste the data, then print to PDF 'Sheet2' all at once?
VBA Code:
Sub print_to_pdf()
Dim sPath As String
sPath = Environ("userprofile") & "\Desktop\"
ActiveSheet.Range("A1:C40").ExportAsFixedFormat Type:=0, _
Filename:=sPath & "Exported Data" & "_" & Format(Now(), _
"yyyymmdd hhmmss"), Quality:=0, IncludeDocProperties:=False, _
openafterpublish:=True
End Sub
I really appreciate any help I can get with this!