I need to save some data by just clicking a button.
It should be easy but I dont know the syntax for vba.
Range("P2:P47").Copy
Sheets("All Data").Select
Range("J2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
I have 2 problem with this code,
1 there is "a lot of" selections that I do not know how to get rid of(I know you should try not to use selections).
2 My real problem is this: cell J2 in the code should not be a determined cell. I would like to have a "lookup value" and search for that in an array, and then using the mathing cell to paste my values.
So in my workbook cell A1 = "Aug 19" and in row 2 all the months are listed. So cell A2 = "Jan 19", B2 = "Feb 19" etc.
I would like to select cell H2 and then pasting by matching my lookup value "Aug 19" to H2 contains "Aug 19"
So in excel formulas I would basically just write:
=HLOOKUP(A1;'All Data'!$B$2:$AL$2;1;FALSE)
Solved problem 1
Sub savedata()
Range("P2:P47").Copy
Worksheets("All Data").Range("J2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
EDIT on problem 2:
Sub savedata()
Range("P2:P47").Copy
ActiveSheet.Range("C3:K3").Find(What:="Aug 19").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
This work as I need it to! Still som questions tho, I couldn't figure out how to reference cell A1 instead of "Aug 19".