excel-vba

VBA “Argument Not Optional” - unsure how to declare variables

╄→尐↘猪︶ㄣ 提交于 2020-01-07 08:35:08
问题 I am trying to write a VBA macro that assigns values to specific cells by calculating the average of the cells directly above and below it. I am running it by selecting the Macros button on the Developer toolbar, then I have to type in the name of my function (it doesn't appear on the list) "interpprob" and select run. I then get a popup that states "Argument is not optional." I'm not quite sure what the problem is. The full macro is below. "tstep" is meant to be an array of the set of rows

Recursion code in VBA

天大地大妈咪最大 提交于 2020-01-07 08:28:14
问题 I am trying to run this code to calculate Q(n) at different Tn in the Equation 16.4 in the attached picture.But its not giving me the correct output. I would appreciate any help. Note: delta1=delta2 =...deltan = dt=1 ( I have taken here ) and further divided S term by 10000 just because in the Equation it is in basis point i.e. 100th part of 1 %. Function Bootstrap(S As Range, Z As Range, L As Double) As Double Dim j As Integer Dim a As Variant Dim b As Variant Dim n As Integer Dim Q() As

How to select the lastrow

我与影子孤独终老i 提交于 2020-01-07 08:16:12
问题 I have an excel sheet it contains data as below: A B C D E F 1 10 11 12 78 45 2 12 15 15 78 45 3 17 18 13 7 45 4 12 45 7 78 78 5 578 54 45 8 78 6 42 72 75 8 78 7 452 22252 2277 87 986 8 752 72 752 878 98638 9 72 72 72 45 78 10 788 72 78 678 465 Now, I want to select the last row in this excel. Because everyday the row number will be change. But I don't want the Selection.End(xlToRight).Select because in this excel blanks will come after every 2 columns. Ex: I want to select A10 to last cell

Change data in vertical table to individual rows using VBA

核能气质少年 提交于 2020-01-07 08:06:08
问题 I have an Excel workbook with the following format: | A | B | C | D | E | |----|-------|-------|-------|-------| 1| | po#1 | po#2 | po#3 | po#1 | 2| | date1 | date2 | date3 | date4 | 3|sku1| qty1 | qty4 | qty7 | qty10 | 4|sku2| qty2 | qty5 | qty8 | qty11 | 5|sku3| qty3 | qty6 | qty9 | qty12 | that I need to convert to the following format: | A | B | C | D | |--------|-------|-------|-------| 1| po#1 | date1 | sku1 | qty1 | 2| po#1 | date1 | sku2 | qty2 | 3| po#1 | date1 | sku3 | qty3 | 4| po

VBA - copying dates from one cell to another - strange change

China☆狼群 提交于 2020-01-07 08:03:51
问题 So, it is rather strange but this is what is happening. In my code I have the following line: tbl_Input.Cells(46 + (l_position - 1) * L_SIZE_BA, 12) = tbl_Input.Cells(46 + (l_position - 2) * L_SIZE_BA, 12) which is supposed to simply take the value of tbl_Input.Cells(a,b) and put it in tbl_Input.Cells(c,d). However, the value of Cells(a,b) is "06.01.2016" and when I run the code I get "07.01.2020". If I take the text property like this, I get what I want correctly: tbl_Input.Cells(46 + (l

VBA - copying dates from one cell to another - strange change

一世执手 提交于 2020-01-07 08:03:33
问题 So, it is rather strange but this is what is happening. In my code I have the following line: tbl_Input.Cells(46 + (l_position - 1) * L_SIZE_BA, 12) = tbl_Input.Cells(46 + (l_position - 2) * L_SIZE_BA, 12) which is supposed to simply take the value of tbl_Input.Cells(a,b) and put it in tbl_Input.Cells(c,d). However, the value of Cells(a,b) is "06.01.2016" and when I run the code I get "07.01.2020". If I take the text property like this, I get what I want correctly: tbl_Input.Cells(46 + (l

Moving data based on information in one column and then sorting by data in another

前提是你 提交于 2020-01-07 07:59:10
问题 Ok so best way to explain this, I have a spreadsheet that is produced monthly. It needs to be automated. From the report that gets shipped into excel I need to take all the data from the project number column and move it to another workbook. In this workbook are worksheets for 2012 and 2013. I need all of the projects starting 300, then 400, then 500 etc to move into the new workbook and then the 2012 projects to go into one worksheet and 2013 into another. How would I go about automating

How to name ADO connection while creating it in Excel VBA

纵饮孤独 提交于 2020-01-07 07:59:10
问题 How to name ADO connection with VBA? Using ADO method of the following VBA code adds new connection which is named by default "Connection" or "Connection2" etc. Sub Make_ADO_Connection() Sheets(2).Cells.ClearContents Dim oCn As ADODB.Connection Dim oRS As ADODB.Recordset Dim ConnString As String Dim SQL As String strFile = ThisWorkbook.FullName ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";" Debug.Print ConnString

Compare ells A3 and A2, if equal, nothing else color row 3 cells A though F. Repeat with next row

六眼飞鱼酱① 提交于 2020-01-07 07:15:08
问题 What I have are a list of contracts below a header row. Some contracts take up multiple rows. What I would like is to have a VBA Macro that will compare cell A3 to A2. If they are the same; next. If they are different, then select the cells A3:F3 and change Interior.Color to grey. Then compare A4 to A3, then A5 to A4 and repeat for all used cells in the A column, effectively making a table. This is what the screen looks like: Row Column A Column B C D E F 1. 000000 (Info) (Info) (Info) (Info)

How to remove leading and trailing spaces from all cells of a excel sheet at once

情到浓时终转凉″ 提交于 2020-01-07 06:56:13
问题 I have a excel sheet which contains lots of data with leading and trailing spaces. Manually removing these spaces with TRIM() takes lot of time. How can I do this efficiently. 回答1: To do this efficiently use a variant array, something like: Sub VBATrim() Dim rng1 As Range Dim rngArea As Range Dim lngRow As Long Dim lngCol As Long Dim lngCalc As Long Dim X() On Error Resume Next Set rng1 = Application.InputBox("Select range for the replacement of non-number", "User select", Selection.Address,