CONTEXT:
I have an empty database set up in Excel which I plan to use to keep track of my monthly expenses for budgeting purposes. What I would like to be able to do is open my spreadsheet, enter in the data from my receipt (date of purchase, type of purchase 'code', and the amount of purchase) and click my "Post Data" macro button to run this macro. I know how to set all of that up, I am just having trouble with writing the macro itself.
THIS IS WHAT I AM LOOKING FOR:
A macro that:
- Finds the correct row which has the date in cell
C2
in columnE
(i.e.row 8
in my example) - Finds the correct column based on the expense code in cell
C2
within the rangeF2:M2
(i.e.column G
in my example) - Pastes the value I have input in cell
C4
into the intersection of the aforementioned row and column (i.e. CellG8
in my example)
WHAT HAS NOT WORKED:
I am able to get the desired result by generating the IF statement (in each of the data cells):
=IFERROR(IF(AND(E5=$C$2,F$2=$C$3),$C$4,""),"")
I was able to record this macro which copies and pastes this statement to all of my data fields (I have an entire year on my spreadsheet). After that, the macro copies and pastes values over the statements. The only problem is that this macro overwrites data previously entered, which is why I felt I needed a more complex macro.
Please point me in the right direction or where I can find out how to do this.
Screenshot (what I am trying to do):
Macro:
Sub CopyPasteData()
'
' CopyPasteData Macro
'
'
Range("F5").Select
ActiveCell.FormulaR1C1 = "=IFERROR(IF(AND(RC5=R2C3,R2C=R3C3),R4C3,""""),"""")"
Range("F5").Select
Selection.Copy
Range("F5:M32").Select
ActiveWindow.SmallScroll Down:=24
Range("F5:M32,F36:M66").Select
Range("F36").Activate
ActiveWindow.SmallScroll Down:=27
Range("F5:M32,F36:M66,F70:M99").Select
Range("F70").Activate
ActiveWindow.SmallScroll Down:=21
Range("F5:M32,F36:M66,F70:M99,F103:M133").Select
Range("F103").Activate
ActiveWindow.SmallScroll Down:=21
Range("F5:M32,F36:M66,F70:M99,F103:M133,F137:M166").Select
Range("F137").Activate
ActiveWindow.SmallScroll Down:=24
Range("F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200").Select
Range("F170").Activate
ActiveWindow.SmallScroll Down:=21
Range("F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200,F204:M234").Select
Range("F204").Activate
ActiveWindow.SmallScroll Down:=24
Range( _
"F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200,F204:M234,F238:M267"). _
Select
Range("F238").Activate
ActiveWindow.SmallScroll Down:=21
Range( _
"F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200,F204:M234,F238:M267,F271:M301" _
).Select
Range("F271").Activate
ActiveWindow.SmallScroll Down:=21
Range( _
"F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200,F204:M234,F238:M267,F271:M301,F305:M334" _
).Select
Range("F305").Activate
ActiveWindow.SmallScroll Down:=24
Range( _
"F5:M32,F36:M66,F70:M99,F103:M133,F137:M166,F170:M200,F204:M234,F238:M267,F271:M301,F305:M334,F338:M368" _
).Select
Range("F338").Activate
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveWindow.ScrollRow = 344
'deleted many lines...
ActiveWindow.ScrollRow = 5
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Application.CutCopyMode = False
Range("F5:M32").Select
ActiveWindow.SmallScroll Down:=-9
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=18
Range("F36:M66").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-15
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F70:M99").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F103:M133").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-9
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F137:M166").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-9
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F170:M200").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=24
Range("F204:M234").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-15
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=36
Range("F238:M267").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-6
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F271:M301").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=33
Range("F305:M334").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("F338:M368").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-12
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ScrollRow = 332
'deleted many lines
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 5
Range("A1").Select
End Sub