Solution for charity

mwfmtl

New Member
Joined
Jan 23, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi all, I am a volunteer for a charity, we have a foodbank, youthclub for boys and girls and various other classes.

We use a powerapp to do the register which populates "present" to each user(row) who is present to column name "Attendance". All I need is a script or macro that will create a column at the end with todays date and then cut the values from attendance to the new created column. I need this to run once a week which i can do via power automate.

I am by no means a coder but I did give it a good try. The below creates the column using today date.

function main(workbook: ExcelScript.Workbook) {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
let x = dd + '/' + mm + '/' + yyyy;

let sh = workbook.getActiveWorksheet()
let tbl = sh.getTable("FBRegister")
tbl.addColumn().setName(x)

}

the below is what doesn't work : m2:m170 being the current attendance column. is it possible to call a variable in get range?

fBRegister.getRange(
"M2:M170").moveTo(fBRegister.getRange("x"));

Any advise will be appreciated.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
the first part was done using typescript to the the column based on today date.
 
Upvote 0
the first part was done using typescript to the the column based on today date.
Welcome to the Board!

I am not familiar with that code (as I suspect many here at this Excel forum aren't).
Is there some reason why you cannot use Excel VBA code?
That is our specialty (being an Excel forum).
 
Upvote 0
Sorry I am happy to use excel macro instead.

1. Create a column at the end of the table with today’s date.
2. Cut values from column named “attended” and paste into the newly created date column.

This macro will run weekly via powerautomate and will allow us to do register weekly on the app.
 
Upvote 0
I am not quite clear. Are you then looking for a PowerAutomate script, or an Excel VBA script?

Also, if would probably be beneficial to see a sample of the data you are working with.
Is this an actual table in Excel?
Can you post a small sample of your table with data so we can see its structure?

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Excel VBA script. I mentioned powerautomate as that will run the macro automatically for me once a week unless we can code that into vba too. mini sheet below


FBRegister1.xlsx
ABCDEFGHIJKLMNOP
1NameHouseholdDate Of BirthEmailGenderHouse NumberFirst Line of AddressPostcodeMobileAttendedID__PowerAppsId__1/1/20238/1/202315-01-202323/01/2023
2Abdul Razzak407/03/1956Female14court avenueE13 5ER755555555Present1365nQ7qYAuVlIPresentPresentPresent
3Jo bells207/03/1956Female 86st georges roadN5 6BT755555555139ju51kZjB2dQPresentPresentPresent
4David Lay107/03/1980Male56downsell roadK6 5ER755555555Present150LCU0Ru5a1AoPresentPresentPresent
5Harsil Patel501/01/1981manshamuthir@gmail.comfemale5newport roadG6 4LR755555555151_r0cRHgtXssPresentPresentPresent
6John Stones307/06/1956Male23jupiter streetG7 8TT755555555Present141SGA0a3ePJe4PresentPresentPresent
7Sam Clark2Male21Holland avenueF6 9TT755555555119FShErTPFq-IPresentPresentPresent
FBRegister
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E2Cell Value="Female"textNO
E2Cell Value="Male"textNO
E3Cell Value="Female"textNO
E3Cell Value="Male"textNO
E4Cell Value="Female"textNO
E4Cell Value="Male"textNO
E5Cell Value="Female"textNO
E5Cell Value="Male"textNO
E6Cell Value="Female"textNO
E6Cell Value="Male"textNO
E7Cell Value="Female"textNO
E7Cell Value="Male"textNO
 
Upvote 0
So, you just want to add a new column to the end of your table, and populate every record in that new column with the value of "Present"?
Is that correct?
 
Upvote 0
So, you just want to add a new column to the end of your table, and populate every record in that new column with the value of "Present"?
Is that correct?
Hi Joe,

Thanks for looking into this. Yes I need a new column named today date. Then i need it populated by the values in column J “Attended”

then i need column J cleared so it has no values. Hope that makes sense?
 
Upvote 0
OK, try this:
VBA Code:
Sub MyAddColumn()

    Dim colName As String
    Dim lc As Long
    Dim lr As Long
    Dim tbl As ListObject
    
'   Set table object by name
    Set tbl = ActiveSheet.ListObjects("FBRegister")
    
'   Get new column name (using today's date)
    colName = Format(Date, "dd-mm-yyyy")
    
'   Find last column in table
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    
'   Find last row in table with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Insert new column to table
    tbl.ListColumns.Add lc + 1
    tbl.HeaderRowRange(lc + 1) = colName
    
'   Copy data from column J
    Range("J2:J" & lr).Copy Range(Cells(2, lc + 1), Cells(lr, lc + 1))
    
'   Clear column J
    Range("J2:J" & lr).ClearContents
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,430
Messages
6,124,851
Members
449,194
Latest member
HellScout

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