0% found this document useful (0 votes)
3 views

Code Macro

This VBA script automates the process of transferring data from the 'Input data' sheet to the 'MASTER DATA' sheet in Excel based on a specified Batch ID. It searches for the Batch ID in column C of the 'MASTER DATA' sheet and, if found, populates various cells in the same row with values from the 'Input data' sheet. A message box confirms successful data entry or alerts if the Batch ID is not found.

Uploaded by

huynvh.work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Code Macro

This VBA script automates the process of transferring data from the 'Input data' sheet to the 'MASTER DATA' sheet in Excel based on a specified Batch ID. It searches for the Batch ID in column C of the 'MASTER DATA' sheet and, if found, populates various cells in the same row with values from the 'Input data' sheet. A message box confirms successful data entry or alerts if the Batch ID is not found.

Uploaded by

huynvh.work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

CODE INPUT DATA TỪ SAP -> Master Data Release

Sub InputData_AutoFindBatch()
Dim srcSheet As Worksheet, dstSheet As Worksheet
Dim batchID As String
Dim foundCell As Range
Dim rowDst As Long

Set srcSheet = ThisWorkbook.Sheets("Input data")


Set dstSheet = ThisWorkbook.Sheets("MASTER DATA")

' Get Batch ID from B3


batchID = srcSheet.Range("B2").Value

' Search for batch ID in column C


Set foundCell = dstSheet.Range("C:C").Find(What:=batchID, LookIn:=xlValues,
LookAt:=xlWhole)

If foundCell Is Nothing Then


MsgBox "Batch not found: " & batchID, vbExclamation
Exit Sub
End If

rowDst = foundCell.Row

' Paste values from Input data to MASTER DATA


With dstSheet
.Cells(rowDst, "R").Value = srcSheet.Range("B4").Value
.Cells(rowDst, "U").Value = srcSheet.Range("B5").Value
.Cells(rowDst, "T").Value = srcSheet.Range("B6").Value
.Cells(rowDst, "S").Value = srcSheet.Range("B7").Value
.Cells(rowDst, "Z").Value = srcSheet.Range("B8").Value
.Cells(rowDst, "X").Resize(1, 2).Value =
Application.Transpose(srcSheet.Range("B9:B10").Value)
.Cells(rowDst, "W").Value = srcSheet.Range("B11").Value
.Cells(rowDst, "AB").Value = srcSheet.Range("B12").Value
.Cells(rowDst, "AA").Value = srcSheet.Range("B13").Value
.Cells(rowDst, "L").Value = srcSheet.Range("B14").Value
.Cells(rowDst, "M").Value = srcSheet.Range("B15").Value
.Cells(rowDst, "O").Value = srcSheet.Range("B16").Value
.Cells(rowDst, "Q").Value = srcSheet.Range("B17").Value
.Cells(rowDst, "V").Value = srcSheet.Range("B18").Value
.Cells(rowDst, "P").Value = srcSheet.Range("B19").Value
.Cells(rowDst, "N").Value = srcSheet.Range("B20").Value
.Range("AD" & rowDst & ":AF" & rowDst).Value =
Application.Transpose(srcSheet.Range("B21").Value)
.Cells(rowDst, "AG").Value = srcSheet.Range("B22").Value
.Cells(rowDst, "AH").Value = srcSheet.Range("B23").Value
.Cells(rowDst, "AI").Value = srcSheet.Range("B24").Value
.Cells(rowDst, "AC").Value = srcSheet.Range("B25").Value
End With

MsgBox "Data successfully entered for batch " & batchID, vbInformation
End Sub

You might also like