JohnGow383
Board Regular
- Joined
- Jul 6, 2021
- Messages
- 141
- Office Version
- 2013
- Platform
- Windows
Hi. I need help with VBA. I'll try to explain clearly what I require and hopefully won't sound too confusing.
I have included a picture to help explain. I have a log. Each day I populate the sheet for the present day's column. The number of columns to the right goes on forever, like as much as Excel will allow. At the end of each day the current day's column will be fully populated.. The data entry rows on each column are row 2 to 22, there is no data to the right of the current day in rows 2 to 22. On rows 24 and 26 there are formula. Each day when rows 2 to 22 are fully populated I copy and paste the values over the formula. The formula remain hidden to the right until at least one cell is populated in the rows 2 to 22. I would like to automate this copy and pasting I have to do every day when the column is complete. I don't require a Worksheet_change trigger, a command button will suffice (in case I have made a mistake). So the criteria would be as follows:
I need to be able to detect the last column in rows 2 to 22. I beleive this code is for for checking say row 2
I would then need a loop to check rows 3 onwards to 22. The starting column can basically be any column after "J" as everything before has formula or text. This is when things get tricky. I would either need a statement to test whether all 21 rows have the same last column index to then fire the copy and paste values of the corresponding column index into rows 24 and 26. OR, when the loop detects the last column with data (would not matter which one) to then count the number of non empty cells. If the number of non empty cells = 0 then to perform the copy and paste scenario as mentioned.
I hope that is clear. Thanks
I have included a picture to help explain. I have a log. Each day I populate the sheet for the present day's column. The number of columns to the right goes on forever, like as much as Excel will allow. At the end of each day the current day's column will be fully populated.. The data entry rows on each column are row 2 to 22, there is no data to the right of the current day in rows 2 to 22. On rows 24 and 26 there are formula. Each day when rows 2 to 22 are fully populated I copy and paste the values over the formula. The formula remain hidden to the right until at least one cell is populated in the rows 2 to 22. I would like to automate this copy and pasting I have to do every day when the column is complete. I don't require a Worksheet_change trigger, a command button will suffice (in case I have made a mistake). So the criteria would be as follows:
I need to be able to detect the last column in rows 2 to 22. I beleive this code is for for checking say row 2
VBA Code:
Dim lc As Integer
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Buddy Log")
lc = ws.Cells(2, Columns.Count).End(xlToLeft).Column
I would then need a loop to check rows 3 onwards to 22. The starting column can basically be any column after "J" as everything before has formula or text. This is when things get tricky. I would either need a statement to test whether all 21 rows have the same last column index to then fire the copy and paste values of the corresponding column index into rows 24 and 26. OR, when the loop detects the last column with data (would not matter which one) to then count the number of non empty cells. If the number of non empty cells = 0 then to perform the copy and paste scenario as mentioned.
I hope that is clear. Thanks