I need to move this search to a userform that currently performs a search on sheet 1 I would like to put the database on sheet 2, everything works but the insert function cannot find the last row.
Private Sub ComboBox1_Change()
Dim Riga As Long
If ComboBox1.Value <> "" Then
Riga = ComboBox1.ListIndex + 2
Cells(Riga, 1).Select
TextBox1 = ComboBox1.Value
TextBox2 = Sheets(2).Cells(ActiveCell.Row, 2)
TextBox3 = Sheets(2).Cells(ActiveCell.Row, 3)
TextBox4 = Sheets(2).Cells(ActiveCell.Row, 4)
TextBox5 = Sheets(2).Cells(ActiveCell.Row, 5)
TextBox6 = Sheets(2).Cells(ActiveCell.Row, 6)
End If
End Sub
Private Sub CommandButton_Chiudi_Click()
Unload Me
End Sub
Private Sub CommandButton_Nuovo_Click()
Dim tx As Byte
ComboBox1.Value = ""
Cells(Range("A1").End(xlDown).Row + 1, 1).Select
For tx = 1 To 6
Userform1.Controls("TextBox" & tx).Text = ""
Next tx
TextBox1.SetFocus
End Sub
Private Sub CommandButton_Cancella_Click()
Dim Messaggio As String, Stile As String, Titolo As String
Dim Risposta As VbMsgBoxResult
Titolo = "Cancellazione Record."
Messaggio = "Vuoi cancellare il tesserino:" & Chr(10) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 1) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 2) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 3) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 4) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 5) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 6) & Chr(10)
Stile = vbYesNo + vbQuestion + vbDefaultButton2
Risposta = MsgBox(Messaggio, Stile, Titolo)
If Risposta = vbNo Then End
ActiveCell.EntireRow.Delete
End
End Sub
Private Sub CommandButton_Aggiorna_Click()
Dim Riga As Long
Dim Messaggio As String, Stile As String, Titolo As String
Dim Risposta As VbMsgBoxResult
Titolo = "Cancellazione Record."
Messaggio = "Vuoi registrare il tesserino:" & Chr(10) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 1).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 2).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 3).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 4).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 5).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 6).Value & Chr(10) & Chr(10) _
& "con:" & Chr(10) _
& TextBox1.Value & Chr(10) _
& TextBox2.Value & Chr(10) _
& TextBox3.Value & Chr(10) _
& TextBox4.Value & Chr(10) _
& TextBox5.Value & Chr(10) _
& TextBox6.Value
Stile = vbYesNo + vbQuestion + vbDefaultButton2
Risposta = MsgBox(Messaggio, Stile, Titolo)
If Risposta = vbNo Then End
Riga = ActiveCell.Row
ComboBox1.Value = ""
Sheets(2).Cells(Riga, 1) = TextBox1.Value
Sheets(2).Cells(Riga, 2) = TextBox2.Value
Sheets(2).Cells(Riga, 3) = TextBox3.Value
Sheets(2).Cells(Riga, 4) = TextBox4.Value
Sheets(2).Cells(Riga, 5) = TextBox5.Value
Sheets(2).Cells(Riga, 6) = TextBox6.Value
ComboBox1.SetFocus
End Sub
how can I do to indicate that with the insert new record function I find the last row on the database that I have moved to sheet 2? thank you
sheets(2).Cells(Range("A1").End(xlDown).Row + 1, 1).Select
it doesn't work and I go into error
There are two easy methods. Try them out use what ever works fine for your case.
Method 1:
Sheets(2).UsedRange.Rows.Count
Method 2:
Sheets(2).Cells(Rows.Count, col_no).End(xlUp).Row
Here you need to change col_no to your desired column. For the above example it would be like
Method 2:
Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
These both method will give you last data containing row you need to add one ( +1 ) to get next blank row for new data entry.
Related
I am trying to automate the creation of labels via VBA.
The code runs into
Run time error 91 - Object variable or With block variable not set
I would like the code to run from label1 (already created in Word), to label24.
These labels are in Word, and get the data from Excel.
Without the loop section the code runs normally, so the problem is in line
UserForm1.Controls("Label" & i).Caption =
When exchanged to the below code, the macro runs normally:
ThisDocument.Label1.Caption =
I am doing this in module section
Sub CreateLabels()
Dim exWb As Object
Set exWb = CreateObject("Excel.Application")
exWb.Workbooks.Open ("C:\Users\xxxx")
Dim i As Integer
Dim UserForm1 As Object
For i = 1 To 24
If exWb.Sheets("Final").Range("I2").Value = _
"" And exWb.Sheets("Final").Range("F2").Value = "" Then
'do not put I2 and F2 values if they are missing
' (as it creates blank row in the label)
UserForm1.Controls("Label" & i).Caption = _
exWb.Sheets("Final").Cells(2, 7) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 8) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 10) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 11)
ElseIf exWb.Sheets("Final").Range("I2").Value = "" Then
UserForm1.Controls("Label" & i).Caption = _
exWb.Sheets("Final").Cells(2, 7) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 6) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 8) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 10) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 11)
ElseIf exWb.Sheets("Final").Range("F2").Value = "" Then
UserForm1.Controls("Label" & i).Caption = _
exWb.Sheets("Final").Cells(2, 7) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 8) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 9) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 10) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 11)
Else: UserForm1.Controls("Label" & i).Caption = _
exWb.Sheets("Final").Cells(2, 7) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 6) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 8) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 9) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 10) & vbCrLf & _
exWb.Sheets("Final").Cells(2, 11)
End If
Next i
Set exWb = Nothing
End Sub
You are declaring a variable UserForm1 but don't instantiate it. This variable will prevent the VBA runtime to create the default instance. Remove this declaration should fix this.
However, you should consider to read the rubberduck-article L8n mentioned in the comments and refactor the code so you don't rely on the default instance. Maybe create the form object and pass it as parameter to your subroutine.
Issue has been resolved by using field:
Dim fld As Field
For Each fld In ThisDocument.Fields
If exWb.Sheets("Final").Range("I2").Value = "" And exWb.Sheets("Final").Range("F2").Value = "" Then
'do not put I2 and F2 values if they are missing (as it creates blank row in the label)
fld.OLEFormat.Object.Caption = exWb.Sheets("Final").Cells(q, 7) & vbCrLf
& exWb.Sheets("Final").Cells(q, 8) _
& vbCrLf & exWb.Sheets("Final").Cells(q, 10) & vbCrLf &
exWb.Sheets("Final").Cells(q, 11)
I have followed jsotola's suggestion and recorded the following macro, but encountered an error, how can I solve it?
Run time error 91 and the following code has been highlighted
Selection.ListObject.TableObject.Refresh
Sub Macro1()
ActiveWorkbook.Queries.Add Name:="1-1-1", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""http://www.hkjc.com/English/racing/Horse.asp?HorseNo=V099""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
ActiveWorkbook.Queries.Add Name:="1-1-2", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""http://www.hkjc.com/English/racing/Horse.asp?HorseNo=V099""))," & Chr(13) & "" & Chr(10) & " Data1 = Source{1}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data1,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
Workbooks("Book1").Connections.Add2 "Query - Table 0", _
"Connection to the 'Table 0' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 0" _
, """Table 0""", 6, True, False
Workbooks("Book1").Connections.Add2 "Query - Table 1", _
"Connection to the 'Table 1' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 1" _
, """Table 1""", 6, True, False
Sheets.Add After:=ActiveSheet
Selection.ListObject.TableObject.Refresh
Sheets.Add After:=ActiveSheet
Selection.ListObject.TableObject.Refresh
End Sub
You could use the following script.
① I grab the left hand side links with
.getElementsByTagName("table")(3).getElementsByTagName("a")
As these return relative paths starting with "about:", I replace this part with the fixed prefix string BASESTRING. This gives the absolute path.
② I target the table with main info by getting get a collection of the table tags and selecting the appropriate table by index.
Set hTable = .getElementsByTagName("table")(6)
③ Additionally, as targeting by className is not supported with method I am using, due to late bound HTMLfile I assume), I parse the sub header out "SMART BOY (V076)" from the innerHTML of an element containing this info. Otherwise, it could have been targeted more cleanly with .getElementsByClassName("subsubheader")(0)
Example data on page:
Example output from code:
Code:
Option Explicit
Public Sub GetTable()
Dim sResponse As String, hTable As Object
Application.ScreenUpdating = False
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://www.hkjc.com/english/racing/horse.asp?HorseNo=V076", False
.send
sResponse = StrConv(.responseBody, vbUnicode)
End With
sResponse = Mid$(sResponse, InStr(1, sResponse, "HEAD"))
With CreateObject("htmlFile")
.Write sResponse
Set hTable = .getElementsByTagName("table")(6)
Dim links As Object, title As String
Set links = .getElementsByTagName("table")(3).getElementsByTagName("a")
title = Replace$(Split(Split(.getElementsByTagName("table")(2).innerHTML, "title_eng_text>")(1), "<")(0), " ", vbNullString)
End With
Dim tSection As Object, tRow As Object, tCell As Object, tr As Object, td As Object, r As Long, c As Long, hBody As Object
Set hBody = hTable.getElementsByTagName("tbody")
Const BASESTRING As String = "http://www.hkjc.com/english/racing/"
With ActiveSheet
.Cells(1, 1) = title
r = 2
For Each tSection In hBody 'HTMLTableSection
Set tRow = tSection.getElementsByTagName("tr") 'HTMLTableRow
For Each tr In tRow
Set tCell = tr.getElementsByTagName("td")
c = 1
.Cells(r, c) = links(r - 1).innerHTML
.Cells(r, c + 1) = Replace$(links(r - 1), "about:", BASESTRING)
For Each td In tCell 'DispHTMLElementCollection
.Cells(r, c + 2).Value = td.innerText 'HTMLTableCell
c = c + 1
Next td
r = r + 1
Next tr
Next tSection
.UsedRange.Columns.AutoFit
End With
Application.ScreenUpdating = True
End Sub
I have a Form in VBA that has a button that will create a new sheet within the workbook.
On that new sheet, I need 4 buttons to be on there with their code already in place.
When I hit the 'create new sheet' button, I have the following code for updating the new buttons on the new sheet:
'Update quantity button
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=150, Top:=20, Width:=123.75, Height _
:=23.25).Select
ActiveSheet.OLEObjects(1).Object.Caption = "Update Quantity"
'update quantity code
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
LineNum = .CountOfLines + 1
.InsertLines LineNum, _
"Private Sub CommandButton1_Click()" & vbLf & _
"Dim ComponentAmt As Double" & vbLf & _
"ComponentNum = Application.InputBox(""Please provide a component number"", ""Component Number"", Type:=1)" & vbLf & _
"ComponentAmt = Application.InputBox(""Quantity received of the component"", ""Quantity Received"", Type:=1)" & vbLf & _
"Set found = Range(""A:A"").Find(what:=ComponentNum, LookIn:=xlValues, LookAt:=xlWhole)" & vbLf & _
"If found Is Nothing Then" & vbLf & _
"MsgBox ""Your component number was not found" & vbLf & _
"Else" & vbLf & _
"found.Offset(0, 2).Value = found.Offset(0,2).Value + ComponentAmt" & vbLf & _
"End If" & vbLf & _
"End Sub"
End With
'Archive button
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=400, Top:=200, Width:=123.75, Height _
:=23.25).Select
ActiveSheet.OLEObjects(2).Object.Caption = "1. Export PO"
'Archive Code
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
LineNum2 = .CountOfLines + 1
.InsertLines LineNum2, _
"Private Sub CommandButton2_Click()" & vbLf & _
"ActiveSheet.Copy" & vbLf & _
"With ActiveSheet.UsedRange" & vbLf & _
".Copy" & vbLf & _
".PasteSpecial xlValue" & vbLf & _
".PasteSpecial xlFormats" & vbLf & _
"End With" & vbLf & _
"Application.CutCopyMode = False" & vbLf & _
"ActiveWorkbook.SaveAs ""Full Path/""" & vbLf & _
"End Sub"
End With
'Hide button
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=400, Top:=250, Width:=123.75, Height _
:=23.25).Select
ActiveSheet.OLEObjects(3).Object.Caption = "2. Done"
'hide button Code
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
LineNum4 = .CountOfLines + 1
.InsertLines LineNum4, _
"Private Sub CommandButton3_Click()" & vbLf & _
"ActiveSheet.Select" & vbLf & _
"ActiveWindow.SelectedSheets.Visible = False" & vbLf & _
"End Sub"
End With
'View price button
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=200, Top:=20, Width:=123.75, Height _
:=23.25).Select
ActiveSheet.OLEObjects(4).Object.Caption = "View Price"
'View price code
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
LineNum4 = .CountOfLines + 1
.InsertLines LineNum4, _
"Private Sub CommandButton4_Click()" & vbLf & _
"Range(""I10"").Select" & vbLf & _
"ActiveCell.FormulaR1C1 = ""=VLOOKUP(R[-8]C[-7],KitList!C[-8]:C[11],17,FALSE)""" & vbLf & _
"Range(""J10"").Select" & vbLf & _
"ActiveCell.FormulaR1C1 = ""=VLOOKUP(R[-8]C[-8],KitList!C[-9]:C[10],18,FALSE)""" & vbLf & _
"Range(""I11"").Select" & vbLf & _
"ActiveCell.FormulaR1C1 = ""=VLOOKUP(R[-9]C[-7],KitList!C[-8]:C[11],19,FALSE)""" & vbLf & _
"Range(""J11"").Select" & vbLf & _
"ActiveCell.FormulaR1C1 = ""=VLOOKUP(R[-9]C[-8],KitList!C[-9]:C[10],20,FALSE)""" & vbLf & _
"End Sub"
End With
The buttons then show on the new worksheet, but when I click on them, nothing happens.
Also, when clicking on the sheet in VBA I have the following code that is supposed to be for the buttons.
Private Sub CommandButton1_Click()
'update quantity
Dim ComponentAmt As Double
ComponentNum = Application.InputBox("Please provide a component number", "Component Number", Type:=1)
ComponentAmt = Application.InputBox("Quantity received of the component", "Quantity Received", Type:=1)
Set found = Range("A:A").Find(what:=ComponentNum, LookIn:=xlValues, LookAt:=xlWhole)
If found Is Nothing Then
MsgBox "Your component number was not found"
Else
found.Offset(0, 2).Value = found.Offset(0, 2).Value + ComponentAmt
End If
End Sub
Private Sub CommandButton2_Click()
'export PO
ActiveSheet.Copy
With ActiveSheet.UsedRange
.Copy
.PasteSpecial xlValue
.PasteSpecial xlFormats
End With
Application.CutCopyMode = False
ActiveWorkbook.SaveAs "Full Path/"
End Sub
Private Sub CommandButton3_Click()
'hides the PO in the document
ActiveSheet.Select
ActiveWindow.SelectedSheets.Visible = False
End Sub
Private Sub CommandButton4_Click()
'view price
Range("I10").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-8]C[-7],KitList!C[-8]:C[11],17,FALSE)"
Range("J10").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-8]C[-8],KitList!C[-9]:C[10],18,FALSE)"
Range("I11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-9]C[-7],KitList!C[-8]:C[11],19,FALSE)"
Range("J11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-9]C[-8],KitList!C[-9]:C[10],20,FALSE)"
End Sub
Should I make the code for each button as a sub then on the buttons call the sub?
If I create more then one new sheet, are the button names going to change?
I have the following code where the adress doen't work... I wonder how I can select the e-mail adress value out of a cell because with cells(1,1).value it doesn't seem to work in my case.
Sub email_missing_forecast()
Application.ScreenUpdating = False
'Déclaration des variables
derniereligne = Range("B").End(xlUp).Row
Adresse = Cells(i, "D").Value
Adresse2 = Cells(i, "E").Value
Adresse3 = Cells(i, "F").Value
Project_number = Cells(1, 2).Value
Project_name = Cells(2, 2).Value
Project_due = Cells(3, 2).Value
Lien = Cells(4, 2).Value
Dim Objoutlook As New Outlook.Application
Dim Objectmail
'Condition
For i = 6 To derniereligne
If Cells(i, "B").Value = "No" Then
Set Objoutlook = New Outlook.Application
Set Objectmail = Outlook.createitem(olmailitem)
With Objectmail
.To = Adresse & ";" & Adresse2 & ";" & Adresse3
.Subject = "Bobbi Brown| " & Project_number & " " & Project_name & "| Forecast due " & Project_due
.Body = "Dear All, " & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & "Please enter your forecast " & "<a href=lien>here.</a>" & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen"
.Send
End with
End If
Next i
Application.ScreenUpdating = True
MsgBox "Your e-mails have been sent successfully", , "FIY"
End Sub
You didn't set i before using it for your Adresse variables, moving the declaration of these variables in your loop should solve your problem:
Sub email_missing_forecast()
Application.ScreenUpdating = False
'Déclaration des variables
derniereligne = Range("B").End(xlUp).Row
Project_number = Cells(1, 2).Value
Project_name = Cells(2, 2).Value
Project_due = Cells(3, 2).Value
Lien = Cells(4, 2).Value
Dim Objoutlook As New Outlook.Application
Dim Objectmail
'Condition
For i = 6 To derniereligne
Adresse = Cells(i, "D").Value
Adresse2 = Cells(i, "E").Value
Adresse3 = Cells(i, "F").Value
If Cells(i, "B").Value = "No" Then
Set Objoutlook = New Outlook.Application
Set Objectmail = Outlook.createitem(olmailitem)
With Objectmail
.To = Adresse & ";" & Adresse2 & ";" & Adresse3
.Subject = "Bobbi Brown| " & Project_number & " " & Project_name & "| Forecast due " & Project_due
.Body = "Dear All, " & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & "Please enter your forecast " & "<a href=lien>here.</a>" & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen"
.Send
End with
End If
Next i
Application.ScreenUpdating = True
MsgBox "Your e-mails have been sent successfully", , "FIY"
End Sub
So I have tried and failed many times to do this.
I'm trying to write a VBA script that when run will insert a comment in the active cell that says:
[Surname], [First Name]
[Todays date] was [current cell value]
Surnames and First Names should be bold.
If the cell is edited again it would edit the comment and put the above format below the previous comment.
Here is what I have at the moment (bearing in mind it could be very wrong)
Sub Test()
Dim UserN As String
Dim commt As String
Dim cmt As Comment
UserN = Application.UserName
Set cmt = ActiveCell.Comment
If ActiveCell.Comment Is Nothing Then
commt = UserN & Chr(10) & Chr(10) _
& Chr(10) & Format(Now, strDate) & " was £" & ActiveCell
With Selection
With Cells(Selection.Row, Selection.Column)
.ClearComments
.AddComment
.Comment.Visible = False
.Comment.Shape.AutoShapeType = msoShapeRoundedRectangle
.Comment.Text Text:=commt
With .Comment.Shape.TextFrame
' Username
With .Characters(1, Len(UserN)).Font
.Bold = True
End With
With .Characters.Font
.Size = 12
End With
End With
.Comment.Shape.TextFrame.AutoSize = True
End With
End With
Else
commt.txt = commt.txt & Chr(10) UserN & Chr(10) & Chr(10)
& Chr(10) & Format(Now, strDate) & " was £" & ActiveCell
With Selection
With Cells(Selection.Row, Selection.Column)
.ClearComments
.AddComment
.Comment.Visible = False
.Comment.Shape.AutoShapeType = msoShapeRoundedRectangle
.Comment.Text Text:=commt
With .Comment.Shape.TextFrame
' Username
With .Characters(1, Len(UserN)).Font
.Bold = True
End With
With .Characters.Font
.Size = 12
End With
End With
.Comment.Shape.TextFrame.AutoSize = True
End With
End With
End If
End Sub
I think the only major issue is with this line:
commt.txt = commt.txt & Chr(10) UserN & Chr(10) & Chr(10)
& Chr(10) & Format(Now, strDate) & " was £" & ActiveCell
It is using the variable 'commt' as if it were a comment object, but is simply a string. It's also missing a '&' and a '_' line separator. I believe the line should be:
commt = cmt.text & Chr(10) & UserN & Chr(10) & Chr(10) & Chr(10) & Format(Now, strDate) & " was £" & ActiveCell