Adding New record

  • Thread starter Thread starter Squid
  • Start date Start date
S

Squid

I have a spreadsheet, where I need to copy certain cell
values and place into a separate sheet. I want this occur
in the BeforePrint event. So, when the user prints the
Check worksheet, the code will populate the specific
sheets with the proper cells values and then position the
cell to the next row. When the user again prints, new data
could be added to the specific sheet without overwriting
the previous data.

Below is the code i have so far, but it is not working.
Could someone please help me?

Thanks.. Mike


Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim strFund As String
Dim strAP As String
Dim sngAmount As Single
Dim i As Integer ' Row
Dim j As Integer ' Column

strFund = Worksheets("Check Worksheet").Range("J2").Value
strAP = Worksheets("Check Worksheet").Range("C14").Value
sngAmount = Worksheets("Check Worksheet").Range
("C22").Value
i = 2 'Row
j = 1 'Column

If strFund = "MEDICAL" Then
Sheets("AP-Medical").Select
Range.Cells(i, j) = strAP
Range.Cells(i, j + 1) = sngAmount
i = i + 1

Else
Sheets("AP-Pension").Select
Range.Cells(i, j) = strAP
Range.Cells(i, j + 1) = sngAmount
i = i + 1
End If


End Sub
 
If strFund = "MEDICAL" Then
Sheets("AP-Medical").Select
do while not isempty(cells(i,j))
i = i + 1
loop
Cells(i, j) = strAP
Cells(i, j + 1) = sngAmount
Else
Sheets("AP-Pension").Select
do while not isempty(cells(i,j))
i = i + 1
Loop
Cells(i, j) = strAP
Cells(i, j + 1) = sngAmount
End If
 
Thank you. THis is exactly what I needed.
-----Original Message-----
If strFund = "MEDICAL" Then
Sheets("AP-Medical").Select
do while not isempty(cells(i,j))
i = i + 1
loop
Cells(i, j) = strAP
Cells(i, j + 1) = sngAmount
Else
Sheets("AP-Pension").Select
do while not isempty(cells(i,j))
i = i + 1
Loop
Cells(i, j) = strAP
Cells(i, j + 1) = sngAmount
End If

--
Regards,
Tom Ogilvy





.
 
Back
Top