I want to insert the content of a cell or a row of cells into a macro to avoid having to update the macro code.
This is so that people at my office can simply update a list in a spreadsheet instead of having to go change the VBA code.
Is it possible to simply ask Excel to insert text from a cell into VBA and use it to execute the macro?
Thank you!
I'm not positive I understand your question, however to read data from a cell you would use
Worksheet(SheetIndex).Cells(x,y).Value
If you want to loop through rows to get the data doing a for loop would be the easiest way around it.
For i to j
'Do Stuff
Next
If you want to loop through all rows in a sheet find the total number of rows by getting number of used cells.
Worksheet(SheetIndex).UsedRange.Rows.Count
Honestly, I would probably have a button to actually trigger the start of this to increase usability. Code should always be written with scalability in mind so why would they need to change the macro code?
Related
So I cut and paste the income statement into an excel spreadsheet, and I was hoping to make a macro that would run in a loop and check each cell one-by-one to see if they had data in it, and if it had data, to cut and paste it to another sheet.
This is the foundation of a bigger project, but I am just stuck on this. I also feel that with the looping code working, I can tweak it to do some of the other stuff I need to do.
To get started in writing a macro like this, it easiest to record the actions you're performing and the review/edit the code. When recording, perform the fewest actions as possible, including avoiding scrolling, so that the code that is generated relates to only the actions you require.
To copy and paste all data excluding blank cells, try using Paste Special and put a tick against Skip Blanks.
I have slightly different data but same format in one excel sheet.
Each data set is 5 columns. The first data set is column A-E, the second data set is column F-J, all the way through to DID-DIH
What I would like to do is to extract these to either their individual sheets or individual workbooks
Is this possible? Perhaps using VBA code?
Sorry I am an amateur trying analyse a massive data set
A good way to get started would be to hit the record macro button and copy the first columns manually. Then stop the recording and look in the VBA editor at the code produced. Wrap this in a loop and make the necessary changes to move columns etc. Have a go and post the code if you get stuck.
I have a .net program that updates values in an excel sheet programmatically using an OLEDB connection.
my excel sheet has some simple SUM formulas that sum the values that are programmatically updated. The problem is that since the values are updated while the excel sheet is closed my formulas do not calculate when the sheet is opened. When I press calculate sheet button the formulas are still not executed (because excel does not recognize that the new values have been added, possibly?). The only way I can get them to execute is if I click on the cell holding the formula (As if to modify the formula) then press enter(making excel reevaluate the cells). I have calculation option set to automatic and my data types are correct (general for the formulas and number for the number values). Is there any way I can make the spreadsheet calculate the formulas when I open it?
Try pressing ctrl+alt+f9 which should force a full calculation and not just a recalculation (like the calculate button does) that looks at cells that have changed.
More info on calculation material can be found here.
For vba I believe it is
Application.CalculateFull
Maybe this will work
Private Sub Workbook_Open()
Worksheets(1).Calculate
End Sub
Just in case someone runs into this problem: To do a full recalculation in vba you can use Application.CalculateFullRebuild to force a full calculation.
I am working with an excel sheet and wondering is there any way you can enter a currency value into a cell without completely removing the previous amount. I am trying to keep a record of numerous previous entries put into the excel sheet. It needs to be enabled so it is just a case of adding the new value and the previous values would be stored in the same cell. I know its a long shot but any help would be seriously appreciated. Would look something like below with the €1000 being the last entry and the €3000 being the first.
€1000
€1300
€1250
€3000
You cannot squeeze more than one value into a cell.
You could write VBA code that could, for example, use the Change event of the worksheet to add a comment to the cell and append the previous value to this comment. Or use this event to copy the previous value to a, perhaps hidden, worksheet.
For completeness I should mention that there is a Track Changes feature in Excel but it requires the workbook to be shared - which I do not recommend. Excel is not designed to work with multiple-users.
Is there a function or such thing in VBA to find distinct values in a range ?
Otherwise i guess I'll just write a Sub using a Collection, but that sounds a little overkill. I am never a big fan of browsing cells in a range. That seems to get things slower.
The way I've done this in the past is to use a worksheet to manipulate the data using the in-built functionality of Excel (rather than VBA specifically).
Record a macro whilst selecting a list of values in a worksheet column, then use the Advanced Filter functionality to 'Copy to Another Location' whilst the 'Unique records only' checkbox is checked.
This will give you a unique list in the destination column, from which you can read the values in VBA and continue what you were doing.
Don't forget to edit out the 'fluff' that recording a macro will inevitably write in for you.