Sub TransferData()
Dim wkb As Workbook, wks As Worksheet, LastRow As Long
Dim FilePath As String, FileName As String
Dim ws As Worksheet, blnOpened As Boolean
'Change these variables as desired...
FilePath = "address" 'change path here
FileName = "name of the file" 'change name here
Call ToggleEvents(False)
Set ws = ThisWorkbook.Sheets("input sheet") 'change source sheet name here
If WbOpen(FileName) = True Then
Set wkb = Workbooks(FileName)
blnOpened = False
Else
If Right(FilePath, 1) <> Application.PathSeparator Then
FilePath = FilePath & Application.PathSeparator
End If
Set wkb = Workbooks.Open(FilePath & FileName)
blnOpened = True
End If
Set wks = wkb.Sheets("master data") 'change destination sheet name here
LastRow = wks.Cells.Find(what:="*", after:=wks.Cells(1, 1), searchorder:=xlByRows, searchdirection:=xlPrevious).Row + 1
wks.Cells(LastRow, "B").Value = ws.Cells(3, "c").Value
wks.Cells(LastRow, "C").Value = ws.Cells(4, "c").Value
wks.Cells(LastRow, "D").Value = ws.Cells(5, "c").Value
wks.Cells(LastRow, "E").Value = ws.Cells(6, "c").Value
wks.Cells(LastRow, "F").Value = ws.Cells(7, "c").Value
wks.Cells(LastRow, "G").Value = ws.Cells(8, "c").Value
wks.Cells(LastRow, "H").Value = ws.Cells(9, "c").Value
wks.Cells(LastRow, "I").Value = ws.Cells(10, "c").Value
wks.Cells(LastRow, "J").Value = ws.Cells(11, "c").Value
wks.Cells(LastRow, "K").Value = ws.Cells(12, "c").Value
wks.Cells(LastRow, "L").Value = ws.Cells(13, "c").Value
wks.Cells(LastRow, "M").Value = ws.Cells(14, "c").Value
wks.Cells(LastRow, "N").Value = ws.Cells(15, "c").Value
wks.Cells(LastRow, "O").Value = ws.Cells(16, "c").Value
wks.Cells(LastRow, "P").Value = ws.Cells(17, "c").Value
wks.Cells(LastRow, "Q").Value = ws.Cells(18, "c").Value
wks.Cells(LastRow, "R").Value = ws.Cells(19, "c").Value
wks.Cells(LastRow, "S").Value = ws.Cells(20, "c").Value
wks.Cells(LastRow, "T").Value = ws.Cells(21, "c").Value
wks.Cells(LastRow, "U").Value = ws.Cells(22, "c").Value
wks.Cells(LastRow, "V").Value = ws.Cells(23, "c").Value
wks.Cells(LastRow, "W").Value = ws.Cells(24, "c").Value
wks.Cells(LastRow, "X").Value = ws.Cells(25, "c").Value
wks.Cells(LastRow, "Y").Value = ws.Cells(26, "c").Value
wks.Cells(LastRow, "Z").Value = ws.Cells(27, "c").Value
wks.Cells(LastRow, "aa").Value = ws.Cells(28, "c").Value
wks.Cells(LastRow, "aB").Value = ws.Cells(29, "c").Value
wks.Cells(LastRow, "aC").Value = ws.Cells(30, "c").Value
wks.Cells(LastRow, "aD").Value = ws.Cells(31, "c").Value
wks.Cells(LastRow, "aE").Value = ws.Cells(32, "c").Value
wks.Cells(LastRow, "aF").Value = ws.Cells(33, "c").Value
wks.Cells(LastRow, "aG").Value = ws.Cells(34, "c").Value
wks.Cells(LastRow, "aH").Value = ws.Cells(35, "c").Value
wks.Cells(LastRow, "aI").Value = ws.Cells(36, "c").Value
wks.Cells(LastRow, "aJ").Value = ws.Cells(37, "c").Value
wks.Cells(LastRow, "aK").Value = ws.Cells(38, "c").Value
wks.Cells(LastRow, "aL").Value = ws.Cells(39, "c").Value
wks.Cells(LastRow, "aM").Value = ws.Cells(40, "c").Value
wks.Cells(LastRow, "aN").Value = ws.Cells(41, "c").Value
wks.Cells(LastRow, "aO").Value = ws.Cells(42, "c").Value
wks.Cells(LastRow, "aP").Value = ws.Cells(43, "c").Value
wks.Cells(LastRow, "aQ").Value = ws.Cells(44, "c").Value
wks.Cells(LastRow, "aR").Value = ws.Cells(45, "c").Value
wks.Cells(LastRow, "aS").Value = ws.Cells(46, "c").Value
wks.Cells(LastRow, "aT").Value = ws.Cells(47, "c").Value
wks.Cells(LastRow, "aU").Value = ws.Cells(48, "c").Value
wks.Cells(LastRow, "aV").Value = ws.Cells(49, "c").Value
wks.Cells(LastRow, "aW").Value = ws.Cells(50, "c").Value
wks.Cells(LastRow, "aX").Value = ws.Cells(51, "c").Value
wks.Cells(LastRow, "aY").Value = ws.Cells(52, "c").Value
wks.Cells(LastRow, "aZ").Value = ws.Cells(53, "c").Value
wks.Cells(LastRow, "ba").Value = ws.Cells(54, "c").Value
wks.Cells(LastRow, "bB").Value = ws.Cells(55, "c").Value
wks.Cells(LastRow, "bc").Value = ws.Cells(56, "c").Value
If blnOpened = True Then
wkb.Close SaveChanges:=True
End If
If MsgBox("Clear values?", vbYesNo, "CLEAR?") = vbYes Then
Call ClearData
End If
Call ToggleEvents(True)
Sheets(Array("sheet1", "sheet2", "sheet3")).Select
Sheets("ELV form").Activate
Application.ActivePrinter = "HP Color LaserJet 4550 PCL6 na Ne05:"
ExecuteExcel4Macro _
"PRINT(1,,,1,,,,,,,,2,""HP Color LaserJet 4550 PCL6 na Ne05:"",,TRUE,,FALSE)"
End Sub
Sub ClearData()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("input sheet") 'change as desired
ws.Range("c3").ClearContents
ws.Range("c5").ClearContents
ws.Range("c6").ClearContents
ws.Range("c7").ClearContents
ws.Range("c8").ClearContents
ws.Range("c9").ClearContents
ws.Range("c10").ClearContents
ws.Range("c11").ClearContents
ws.Range("c12").ClearContents
ws.Range("c13").ClearContents
ws.Range("c14").ClearContents
ws.Range("c15").ClearContents
ws.Range("c16").ClearContents
ws.Range("c17").ClearContents
ws.Range("c18").ClearContents
ws.Range("c19").ClearContents
ws.Range("c20").ClearContents
ws.Range("c21").ClearContents
ws.Range("c22").ClearContents
ws.Range("c23").ClearContents
ws.Range("c24").ClearContents
ws.Range("c25").ClearContents
ws.Range("c26").ClearContents
ws.Range("c27").ClearContents
ws.Range("c28").ClearContents
ws.Range("c29").ClearContents
ws.Range("c30").ClearContents
ws.Range("c31").ClearContents
ws.Range("c32").ClearContents
ws.Range("c33").ClearContents
ws.Range("c34").ClearContents
ws.Range("c35").ClearContents
ws.Range("c36").ClearContents
ws.Range("c37").ClearContents
ws.Range("c38").ClearContents
ws.Range("c39").ClearContents
ws.Range("c40").ClearContents
ws.Range("c41").ClearContents
ws.Range("c42").ClearContents
ws.Range("c43").ClearContents
ws.Range("c44").ClearContents
ws.Range("c45").ClearContents
ws.Range("c46").ClearContents
ws.Range("c47").ClearContents
ws.Range("c48").ClearContents
ws.Range("c49").ClearContents
ws.Range("c50").ClearContents
ws.Range("c51").ClearContents
ws.Range("c52").ClearContents
ws.Range("c53").ClearContents
ws.Range("c54").ClearContents
ws.Range("c55").ClearContents
ws.Range("c56").ClearContents
End Sub
Sub ToggleEvents(blnState As Boolean)
'Originally written by firefytr
With Application
.DisplayAlerts = blnState
.EnableEvents = blnState
.ScreenUpdating = blnState
If blnState Then .CutCopyMode = False
If blnState Then .StatusBar = False
End With
End Sub
Function WbOpen(wbName As String) As Boolean
'Originally found written by Jake Marx
On Error Resume Next
WbOpen = Len(Workbooks(wbName).Name)
End Function
This code is added to a button
Bookmarks