Hi
I have an input screen (input sheet) where I enter data, I then click a "add" button and based on the wording in cell F it copys data A6:D6 to the correct table on a different sheet ("chart of accounts") using the next available row in the table.
I've managed to get to work with one criteria using the word "cash", to go into a table on a different worksheet also called "cash", I'm needing to do it for multiple words such as "Bank" to go in to a table called "Bank" on chart of accounts sheet.
Below is the code I have so far, thank you in advance:
For Each cell In Sheets("Input Sheet").Range("F:F")
If cell.Value = "Cash" Then
Dim config, itm, arr
Dim rw As Range, listCols As ListColumns
Set shtForm = Worksheets("Input Sheet") '<< data source
With Sheets("Chart of Accounts").ListObjects("Table2")
Set rw = .ListRows.Add.Range 'add a new row and get its Range
Set listCols = .ListColumns 'get the columns collection
End With
config = Array("Date<>A6", "Company<>B6", "Reference<>C6", "Amount<>D6")
'loop over each item in the config array and transfer the value to the
' appropriate column
For Each itm In config
arr = Split(itm, "<>") ' split to colname and cell address
rw.Cells(listCols(arr(0)).Index).Value = shtForm.Range(arr(1)).Value
Next itm
End If
Next
End Sub
I have an input screen (input sheet) where I enter data, I then click a "add" button and based on the wording in cell F it copys data A6:D6 to the correct table on a different sheet ("chart of accounts") using the next available row in the table.
I've managed to get to work with one criteria using the word "cash", to go into a table on a different worksheet also called "cash", I'm needing to do it for multiple words such as "Bank" to go in to a table called "Bank" on chart of accounts sheet.
Below is the code I have so far, thank you in advance:
For Each cell In Sheets("Input Sheet").Range("F:F")
If cell.Value = "Cash" Then
Dim config, itm, arr
Dim rw As Range, listCols As ListColumns
Set shtForm = Worksheets("Input Sheet") '<< data source
With Sheets("Chart of Accounts").ListObjects("Table2")
Set rw = .ListRows.Add.Range 'add a new row and get its Range
Set listCols = .ListColumns 'get the columns collection
End With
config = Array("Date<>A6", "Company<>B6", "Reference<>C6", "Amount<>D6")
'loop over each item in the config array and transfer the value to the
' appropriate column
For Each itm In config
arr = Split(itm, "<>") ' split to colname and cell address
rw.Cells(listCols(arr(0)).Index).Value = shtForm.Range(arr(1)).Value
Next itm
End If
Next
End Sub