Currently, I'm trying to code a worksheet to be a logbook. the logs will be on sheet "Log_Master". I have a button that I will attach to my macros to run the script that will take selected information from "Log_Master" to another page named "Summary" with a table also named "summary". At the click of the button (Shift Change), I want information in certain cells to be written to the summary table. Each time the button is pressed I want the information to write to the next row on the table. I already have the sheet "Summary" and the table "Summary" being created via TypeScript (I can send code if needed). Could I complete this task in typeScript?
Some of the information is also in tables. one named "Runtime" and one named "Levels.
Then, I want to do some other functions that I will focus on after I complete this task.
So far, I have successfully moved the data to the other table via copy and paste code:
Sub Autofill_Summary()
'
' autofill_summary Macro
'
'
Sheets("Log_Master").Select
Range("levels[[Silo 1]:[Water Level]]").Select
Selection.Copy
Sheets("Summary").Select
Range("summary[Silo 1]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Log_Master").Select
Range("runtime[[Runtime]:[Ave Moist]]").Select
Selection.Copy
Sheets("Summary").Select
Range("summary[Runtime]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Log_Master").Select
Range("L1").Select
Selection.Copy
Sheets("Summary").Select
Range("summary[Date]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Log_Master").Select
Range("N1").Select
Selection.Copy
Sheets("Summary").Select
Range("summary[Shift]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Log_Master").Select
Range("P1").Select
Selection.Copy
Sheets("Summary").Select
Range("summary[Name]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Log_Master").Select
Range("C2").Select
End Sub
If this method is acceptable, how would i make it to where each time the button is selected it runs the macros and paste the information to the next row on sheet "Summary" in table "Summary"?
I also successfully moved the cell values to the "Summary" sheet but failed to land the data in the table and failed to get the information to populate in the next row. code:
Sub autoFill_Trial()
Dim A As String
Dim B As String
Dim C As String
Dim D As String
Dim E As String
Dim F As String
Dim G As String
Dim H As String
Dim I As String
Dim J As String
Dim K As String
Dim L As String
A = Sheets("Log_Master").Cells(1, 12).Value
B = Sheets("Log_Master").Cells(1, 14).Value
C = Sheets("Log_Master").Cells(1, 16).Value
D = Sheets("Log_Master").Cells(45, 6).Value
E = Sheets("Log_Master").Cells(45, 7).Value
F = Sheets("Log_Master").Cells(45, 8).Value
G = Sheets("Log_Master").Cells(45, 9).Value
H = Sheets("Log_Master").Cells(47, 6).Value
I = Sheets("Log_Master").Cells(47, 7).Value
J = Sheets("Log_Master").Cells(47, 8).Value
K = Sheets("Log_Master").Cells(47, 9).Value
L = Sheets("Log_Master").Cells(47, 10).Value
lastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("Summary").Cells(lastRow + 1).Value = A
Sheets("Summary").Cells(lastRow + 2).Value = B
Sheets("Summary").Cells(lastRow + 3).Value = C
Sheets("Summary").Cells(lastRow + 4).Value = D
Sheets("Summary").Cells(lastRow + 5).Value = E
Sheets("Summary").Cells(lastRow + 6).Value = F
Sheets("Summary").Cells(lastRow + 7).Value = G
Sheets("Summary").Cells(lastRow + 8).Value = H
Sheets("Summary").Cells(lastRow + 9).Value = I
Sheets("Summary").Cells(lastRow + 10).Value = J
Sheets("Summary").Cells(lastRow + 11).Value = K
Sheets("Summary").Cells(lastRow + 12).Value = L
Sheets("Log_Master").Select
Range("C2").Select
End Sub
If someone could help me I would GREATLY appreciate it!
EDIT::::: Adding the typeScript for "Summary" table
function main(workbook: ExcelScript.Workbook) {
// Your code here
//set names for tables to pull info from sheet Log_Master
tbl1=runtime tbl2=levels tblsmy=summary tblmas=runmaster
let tbl1 = workbook.getTable('runtime')
let tbl2 = workbook.getTable('levels')
let tblsmy = workbook.getTable('summary')
let tblmas = workbook.getTable('runmaster')
// look for "Summary" worksheet, delete if it's present.
workbook.getWorksheet('Summary')?.delete();
// Create a new worksheet named "Summary" for the combined table.
const newSheet = workbook.addWorksheet('Summary');
//Assign the "Summary" worksheet to the smy variable
let smy = workbook.getWorksheet('Summary');
// Add a new table at range B1 on summary (smy)
let newTable = workbook.addTable(smy.getRange("B1:M1"), false);
// Set range B1:L1 on summary (smy)
smy.getRange("B1:M1").setValues([["Date", "Shift", "Name", "Runtime", "Downtime", "Fineness", "Moisture", "Silo 1", "Silo 2", "Propane 1", "Propane 2", "Water Level"]]);
// Rename table newTable to "summary" (tblsmy)
newTable.setName("summary");
// Auto fit the columns of range E:L on summary (smy)
//custom size B:D, Set Date Format (B) set
Percent Format (G:M),
let dateRange=smy.getRange("B:B");
dateRange.setNumberFormat("m/d/yyyy;@");
let dtRange=smy.getRange("F:F");
dtRange.setNumberFormat("HH:MM")
let percentRange=smy.getRange("G:M");
percentRange.setNumberFormat("0.00%");
smy.getRange("E:M").getFormat().autofitColumns();
smy.getRange("B:D").getFormat().setColumnWidth(76);
smy.getFreezePanes().freezeAt(smy.getRange("1:1"));
````