ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding New record (https://www.excelbanter.com/excel-programming/284289-adding-new-record.html)

Squid[_2_]

Adding New record
 
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

Tom Ogilvy

Adding New record
 
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


"Squid" wrote in message
...
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




Squid[_2_]

Adding New record
 
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


"Squid" wrote in

message
...
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



.



All times are GMT +1. The time now is 08:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com