Forum Discussion
_Random_Excel_User_
Sep 16, 2022Copper Contributor
VBA code help needed
Hello, I have been trying to figure out a simpler way to copy information over from one worksheet that the data changes on daily, over to another worksheet that compiles the information for each day ...
_Random_Excel_User_
Sep 16, 2022Copper Contributor
HansVogelaar The macro didn't do anything when I ran it and I'm not sure how to troubleshoot the macro.
HansVogelaar
Sep 20, 2022MVP
Thank you for your private message. The layout of the September sheet is partly different from your description in the first post, so the code had to be modified. I also made it a bit simpler for you to read and adjust, if necessary.
Sub CopyData()
Dim ws As Worksheet
Dim wt As Worksheet
Dim rng As Range
Dim r As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Inventory Summary")
Set wt = Worksheets("September")
Set rng = wt.Range("A:A").Find(What:=ws.Range("H3").Value, LookIn:=xlValues, LookAt:=xlWhole)
If rng Is Nothing Then
MsgBox "Date not found!", vbCritical
Else
r = rng.Row
wt.Range("D" & r).Value = ws.Range("B4").Value
wt.Range("E" & r).Value = ws.Range("B5").Value
wt.Range("F" & r).Value = ws.Range("B6").Value
wt.Range("H" & r).Value = ws.Range("B9").Value
wt.Range("I" & r).Value = ws.Range("B10").Value
wt.Range("J" & r).Value = ws.Range("B11").Value
wt.Range("K" & r).Value = ws.Range("B12").Value
wt.Range("L" & r).Value = ws.Range("B13").Value
wt.Range("N" & r).Value = ws.Range("B15").Value
wt.Range("O" & r).Value = ws.Range("B17").Value
wt.Range("P" & r).Value = ws.Range("B18").Value
wt.Range("Q" & r).Value = ws.Range("B19").Value
wt.Range("R" & r).Value = ws.Range("B20").Value
wt.Range("S" & r).Value = ws.Range("B21").Value
wt.Range("T" & r).Value = ws.Range("B22").Value
wt.Range("V" & r).Value = ws.Range("B23").Value
wt.Range("W" & r).Value = ws.Range("B24").Value
wt.Range("Y" & r).Value = ws.Range("B26").Value
End If
Application.ScreenUpdating = True
End Sub
See the attached version, now a macro-enabled workbook (.xlsm). You'll have to allow macros when you open it.
- _Random_Excel_User_Sep 20, 2022Copper ContributorAm I able to run the macro from the PERSONAL worksheet so the file doesn't have to be saved as macro-enabled workbook? My company won't let me save the file as .xlsm.
- HansVogelaarSep 20, 2022MVP
Yes, you can store the macro in a module in your PERSONAL.XLSB workbook.
Make sure that the target workbook is the active workbook when you run the macro.