Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel previous worksheet

Status
Not open for further replies.

dmccallum

Programmer
Jan 5, 2001
90
US
I maintain payment records, one sheet per customer. I want to be able to find the last payment made, calculate the time difference between today and the last payment made, and copy those individuals names and addresses to the last sheet named "BP". My formula works for the first sheet but after I have pasted the info from the first sheet to BP I can't see how to get back to the second sheet, third, etc. So far it goes like this:

Sub LastCell()
'
' LastCell Macro
' Macro recorded 4/27/2001 by D. McCallum

For Each sht In Workbooks("BCLS.xlw").Worksheets

Selection.SpecialCells(xlCellTypeLastCell).Select
ActiveCell.Offset(0, -254).Range("A1").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=TODAY()-R[-1]C[1]"
ActiveCell.Offset(1, 0).Range("A1").Select


If ActiveCell.FormulaR1C1 > 35 Then
Rows("9:10").Select
Range("A10").Activate
Selection.Copy
Sheets("BP").Select
Selection.Insert Shift:=xlDown
Range("A3").Select
End If

Next sht

End Sub

Eventually I would like to be able to have Word create the payment late letter for for now I just need help in getting around the sheets.
 
First you want to change the code in the If statement to this:

sht.Rows("9:10").Copy
Sheets("BP").Rows("1:1").Insert Shift:=xlDown

I tested your code and it had no problem moving through all the sheets.

Try it with my code and let me know what happens.
 
Your input was just what I needed. I've made some modifications in the effort of efficiency and for a while it was not going to the next sheet but it's doing much better now.

Sub FindBal()
'
' FindBal Macro
' Macro recorded 5/1/2001 by D. McCallum
'
For Each sht In Workbooks("BCLS.xls").Worksheets

'
Selection.SpecialCells(xlCellTypeLastCell).Select
Selection.End(xlToLeft).Select
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.End(xlUp).Select
ActiveCell.Offset(0, 7).Range("A1").Select
Bal = ActiveCell.Value
Ans = MsgBox("Balance is ", , Bal)
If Bal > 0 Then
Selection.SpecialCells(xlCellTypeLastCell).Select
ActiveCell.Offset(0, -254).Range("A1").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
ActiveCell.Offset(-1, 1).Range("A1").Select
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Days = ActiveCell.Value
Ans = MsgBox("Days is ", , Days)
If Days > 35 Then
sht.Rows("9:11").Copy
Sheets("BP").Rows("1:1").Insert Shift:=xlDown
End If
End If
Next sht
End Sub

I now check for a zero balance and then check for the days since last payment. Do you have any further suggestions and do you know how to get the list I'm creating into Word for a mail merge?
 
Once you have it doing what you want it to do, you could email me an example of the data and the word document and I could explain how to set up Mail Merge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top