I have built a macro to allow me to match names of people paying subs with my members list in Excel 2007. It is a slightly changed version of a procedure which worked very well in Excel 1997. The macro uses a form containing an amount box, a name list and 3 procedure command buttons and loads the data values to specific cells in a CONTROL worksheet. The amount and the process transfer accurately; the selected name does not transfer. Help in finding the reason will be much appreciated. The macro code is as follows:
#
#
Thanks for your help
David Eagles
Moderator's Edit: Use code tags when posting code. To do so in future, select your code and click on the # icon at the top of your post window.
#
Code:
Sub MacroSubs()
'
' MacroAddSubs Macro
' Macro recorded 14/01/2012 by Eagles
'
MemberWorkbook = ActiveWorkbook.Name
Confirm = "NO"
Do
StatementDate = UCase(InputBox("Date of Payments(s)as dd-mmm-yy:"))
If StatementDate = "END" Then
MsgBox "Process aborted at your request"
Exit Sub
End If
TestChar3 = Mid(StatementDate, 3, 1)
TestChar7 = Mid(StatementDate, 7, 1)
If TestChar3 <> "-" Or TestChar7 <> "-" Then GoTo EndDate
Confirm = UCase(InputBox("Type YES if " & StatementDate & " is correct"))
EndDate:
Loop While Confirm <> "YES"
Workbooks.Add
Columns("B:B").Select
Selection.NumberFormat = "$#,##0.00"
Range("A1") = "Subscriptions received via Bank Transfer"
Range("A2") = "Received on " & StatementDate
Range("A4") = "Member Name"
Range("B4") = "Amount Paid"
ReportRow = 5
ActiveWorkbook.SaveAs FileName:="C:\Data Folder\David\TSB RSA\SUBS " & Range("A2")
ReportWorkbook = ActiveWorkbook.Name
TransactionTotal = 0
Do ' Loop at EndProcess
If ActiveWorkbook.Name <> MemberWorkbook Then
Workbooks(MemberWorkbook).Activate
End If
Sheets("CONTROL").Select
Call ReceiveSubs_Initialize
Range("B2") = StatementDate
Range("B3") = vbNullString ' Amount
Range("B4") = vbNullString ' Name
Range("B5") = vbNullString ' Result
Range("B6") = Format(TransactionTotal, "$##,##0.00")
Range("B7") = vbNullString ' Member Row
ReceiveSubs.Show
FormResult = Range("B5")
If FormResult = "END" Then GoTo EndProcess
AmountSub = Val(Range("B3")) <-------------------- Returned value is correct
If FormResult = "NO" Then GoTo ReportIt
NameSub = Range("B4") <-------------------- Returned value is 'Empty', although the list displayed is complete and accurate
Member = vbNullString
Sheets("MEMBER").Select
For x = 2 To 299
Member = Range("F" & x)
If Member = "" Then
Exit For
End If
If NameSub = Member Then
Exit For
End If
Next x
If NameSub <> Member Then
MsgBox "Error - Selected Member not found"
Exit Sub
End If
Range("S" & x) = StatementDate
Sheets("CONTROL").Select
Range("B7") = x
GoTo ReportIt
ReportIt:
Workbooks(ReportWorkbook).Activate
NewPage = ReportRow Mod 43
If NewPage = 0 Then
Range("A" & ReportRow).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
Range("A" & ReportRow) = "Subscriptions received via Bank Transfer"
Range("A" & ReportRow) = "Received on " & Date & " continued"
Range("A" & ReportRow) = "Member Name"
Range("B" & ReportRow) = "Amount Paid"
ReportRow = ReportRow + 5
End If
If FormResult = "NO" Then
Range("A" & ReportRow) = UCase(InputBox("Enter Stated Name"))
Range("C" & ReportRow) = "** Payer is not recognised **"
Else
Range("A" & ReportRow) = Member
End If
Range("B" & ReportRow) = Format(AmountSub, "$##,##0.00")
ReportRow = ReportRow + 1
TransactionTotal = TransactionTotal + AmountSub
EndProcess:
Loop Until FormResult = "END"
If ActiveWorkbook.Name <> ReportWorkbook Then
Workbooks(ReportWorkbook).Activate
End If
ReportRow = ReportRow + 1
Range("A" & ReportRow) = "Transaction Total"
Range("B" & ReportRow) = TransactionTotal
ActiveWorkbook.Save
Workbooks(MemberWorkbook).Activate
ActiveWorkbook.Save
MsgBox "Process for " & StatementDate & " completed"
End Sub
Private Sub ReceiveSubs_Initialize()
ReceiveSubs.ReceiveAmount.SetFocus
End Sub
Private Sub ReceiveEnd_Click()
ReceiveSubs.Hide
Range("B5") = "END"
End Sub
Private Sub ReceiveNoMember_Click()
ReceiveSubs.Hide
Range("B5") = "NO"
End Sub
Private Sub ReceiveProcess_Click()
ReceiveSubs.Hide
Range("B5") = "PROCESS"
End Sub
Thanks for your help
David Eagles
Moderator's Edit: Use code tags when posting code. To do so in future, select your code and click on the # icon at the top of your post window.