VBA script for checking date, matching date, and publishing data in corresponding cell

kshealy

New Member
Joined
May 2, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello! I'm looking for help with an intricate vba script to perform a task. The task is as follows:

The "Master production" sheet contains production information based off a date in cell C1. For example: a machine ran for x hours.
I need the "Daily Production" sheet to be a duplication of these production values in the "master production" sheet. (can just be the values and not the original formula)
I need it to check the date in "Master Production" sheet cell C1, match that date to column A in the "Daily Production" sheet, and post the values to the corresponding cell.

SIDE NOTE: the tag found in B11 in master production is the same tag as B1 in daily report.

Here's a screen shot of the file.

it would be awesome if this script could run automatically at midnight.
 

Attachments

  • master production.png
    master production.png
    13.9 KB · Views: 12
  • daily report.png
    daily report.png
    9.1 KB · Views: 13

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello! I'm looking for help with an intricate vba script to perform a task. The task is as follows:

The "Master production" sheet contains production information based off a date in cell C1. For example: a machine ran for x hours.
I need the "Daily Production" sheet to be a duplication of these production values in the "master production" sheet. (can just be the values and not the original formula)
I need it to check the date in "Master Production" sheet cell C1, match that date to column A in the "Daily Production" sheet, and post the values to the corresponding cell.

SIDE NOTE: the tag found in B11 in master production is the same tag as B1 in daily report.

Here's a screen shot of the file.

it would be awesome if this script could run automatically at midnight.
also here's what i have... it seems to be close but its telling me there's no matching date...
Sub PublishToDailyProduction()
Dim wsMaster As Worksheet
Dim wsDaily As Worksheet
Dim masterDate As Integer
Dim targetRow As Long
Dim publishRange As Range

' Set the master and daily production worksheets
Set wsMaster = ThisWorkbook.Sheets("Master Production")
Set wsDaily = ThisWorkbook.Sheets("Daily Production")

' Get the date from cell C1 in Master Production sheet
masterDate = wsMaster.Range("C1").Value

' Find the matching row in Daily Production sheet based on the date
On Error Resume Next ' In case there's no match, proceed to error handling
targetRow = Application.WorksheetFunction.Match(masterDate, wsDaily.Columns(A), 0)
On Error GoTo 0 ' Reset error handling

If targetRow > 0 Then ' If match found
' Define the range to be published from Master Production sheet
Set publishRange = wsMaster.Range("B13:X13")

' Publish the range to the corresponding row in Daily Production sheet
publishRange.Copy Destination:=wsDaily.Range("B" & targetRow)

' Optional: Clear contents of the target row in Daily Production sheet before pasting
' wsDaily.Rows(targetRow).ClearContents

' Optional: Adjust formatting or any additional operations

MsgBox "Range published successfully to Daily Production sheet, row " & targetRow, vbInformation
Else
MsgBox "No matching date found in Daily Production sheet.", vbExclamation
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,111
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top