Forum Discussion
OJBridger
May 24, 2022Copper Contributor
VBA Code to write cell values to another sheet
Hi!
I have the below VBA code that takes cell values from rows B5:U5, and then writes a copy of that data to another set of columns to store a 'history' (these figures then get updated from a query when new data arrives).
I now want to modify this so it writes the data to another sheet in the excel file to tidy things up, and then I can have a "data" worksheet I can then use.
Public Sub ButtonOnClick()
Application.EnableEvents = False
Me.Range("W" & Me.Rows.Count).End(xlUp).Offset(1).Resize(, 20).Value = Me.Range("B5:U5").Value
Application.EnableEvents = True
End Sub
How would I modify this to no longer paste this data in W:AQ, but instead pastes it to AnotherWorksheet!: A:U?
All of the solutions I have tried to implement have given me errors so far.
Many thanks in advance!
Try
Public Sub ButtonOnClick() Application.EnableEvents = False With Worksheets("History") .Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(, 20).Value = Me.Range("B5:U5").Value End With Application.EnableEvents = True End Sub
1 Reply
Try
Public Sub ButtonOnClick() Application.EnableEvents = False With Worksheets("History") .Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(, 20).Value = Me.Range("B5:U5").Value End With Application.EnableEvents = True End Sub