小编exc*_*guy的帖子

VBA/SQL,无效使用Null

我在excel中使用userform在我的电子表格之间运行一些内部查询.但是我得到了Invalid Use of Null并且我知道nz空语法(SQL MS Access - 无效使用Null)但是我的查询可能非常大,我想知道是否有任何我可以添加到我的vba代码以允许空值.

这是我的查询,

select [EUC_ID],
RiskReportProductType,
[Source Currency of the CUSIP that is denominated in],
[EnterpriseCurrency],[EnterpriseSector],
[RatingCombo],
iif(RiskReportProductType in ('Equity|Private','Equity|Public','Seed Capital','Pref Shares','GLadjustment','OtherAdjustment'),'n/a',
switch(
[EnterpriseRating] = 'No Rating','BBB',
[EnterpriseRating] <> 'No Rating',[EnterpriseRating],
[EnterpriseRating] is null,'Unmapped - no rating mapping for ' & [RatingCombo],
)) as [EnterpriseRating],
[Issuer],

iif(RiskReportProductType in ('Bond|Corporate','Hybrid','CMBS|CAD','MBS|CAD','Loan Substitute securities'),
switch(
[EnterpriseCurrency] is null, 'Unmapped - no currency mapping for ' & [Source Currency of the CUSIP …
Run Code Online (Sandbox Code Playgroud)

sql excel ms-access access-vba

12
推荐指数
1
解决办法
538
查看次数

VBA,将PDF合并为一个PDF文件

我正在尝试使用vba将PDF组合成一个单独的pdf.我想不使用插件工具,并尝试使用下面的acrobat api.

我尝试了类似的东西,但似乎无法让它发挥作用.我没有错误消息,但也许我错过了部分.

任何帮助,将不胜感激.

   Sub Combine()


   Dim n As Long, PDFfileName As String

    n = 1
    Do
        n = n + 1
        PDFfileName = Dir(ThisWorkbook.Path & "firstpdf" & n & ".pdf")
        If PDFfileName <> "" Then
            'Open the source document that will be added to the destination
            objCAcroPDDocSource.Open ThisWorkbook.Path & "pathwithpdfs" & PDFfileName
            If objCAcroPDDocDestination.InsertPages(objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0) Then
                MsgBox "Merged " & PDFfileName
            Else
                MsgBox "Error merging " & PDFfileName
            End If
            objCAcroPDDocSource.Close
        End If
    Loop …
Run Code Online (Sandbox Code Playgroud)

excel excel-vba

12
推荐指数
1
解决办法
1万
查看次数

VBA /公式,工作表之间的映射

我有一个代码,我在excel 2013上运行时遇到了麻烦.2010年工作正常.

我一直在考虑做公式,因为我无法让它发挥作用.

这是逻辑

  1. 如果存在这种情况,则仅填写表X中的值:在表A中,如果列a =值1,值2或值3且列b <>值4,<>值5

  2. 然后从表单X中查找标题到表单Y.这些标题将位于表Y列c中.

  3. 对于与表Y col c匹配的标题,找到表X.列c和表Y的数据.列d.将这些用作查找表Y中的下一列.对于存在不匹配的地方,使用'OTHERS'作为值.

  4. 对于匹配的标题/列,返回表Y列e(值)并乘以表X.列d.减一.

  5. 将所有这些值返回到标题所在的表单.

表X(实际上计算堆栈和溢出列中的公式)

+-------------+-------------+------------+-------+-----------------+-------------+
|  conditions | condition 2 | currency   | value |     stack       |  overflow   |
+-------------+-------------+------------+-------+-----------------+-------------+
| value 1     | value 10    | USD        |   100 | 100 * (.75 - 1) |             |
| value 2     | value 7     | XRP        |   200 | 200 * (.50 - 1) |             |
| value 3     | value 8     | USD        |   300 |                 | 300*(.65-1) | …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

9
推荐指数
1
解决办法
522
查看次数

Excel 2013 中的代码“无响应”。转换为公式/新代码

我有下面的代码可以在 Excel 2010 中运行。

我升级到 2013,现在遇到无响应问题。

我尝试用 16 个公式 EE2:ET6141 替换此代码。我发现这效率低下、耗时且占用大量内存。

公式来替换我的代码:

IF(AND(OR($BM:$BM="value1",$BM:$BM="value2",$BM:$BM="value3"),$BN:$BN<>"Excel",$BN:$BN<>"ITS"),$AT:$AT*(IFNA(VLOOKUP(EE$1&$S:$S,EQ_Shocks!E:F,2,FALSE),VLOOKUP(EE$1&"OTHERS",EQ_Shocks!E:F,2,FALSE))-1),"")

逻辑类似于:
对于 A1 = Stackoverflow、BM = value1 或 value2 或 value3 的每一行,并且 BN 不在 Excel 中,也不在 ITS 中。然后从 EQ_shocks 表中获取值。

代码

它在这一行出现无响应错误,If thisEqShocks(1, 1) = "#EMPTY" Then 我在该行放置了一个断点end if ,并且尝试循环这个大 if 语句需要很长时间或没有响应。

我还在 for 循环中注意到这一点,For thisScen = 1 To UBound(stressScenMapping, 1)需要很长时间才能通过断点进行响应,Next thisScen我可以肯定地说这是代码的这一部分。

Public Sub oldcode() 
    Application.ScreenUpdating = False

    Dim i As Long, thisScen As Long, nRows As Long, nCols As Long …
Run Code Online (Sandbox Code Playgroud)

excel vba

5
推荐指数
0
解决办法
250
查看次数

VBA,Acrobat Pro将页眉和页脚添加到Pdf

我使用acrobat xi pro和vba来组合我的pdf文件.

我有一个代码,使用acrobat api将pdf页面附加在一起:https: //wwwimages2.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf

但是,我正在尝试自动为页面编号,或添加我自定义保存的页眉和页脚设置并应用于所有页面.

在此输入图像描述 在此输入图像描述 在此输入图像描述

这是我的代码:

   Dim acroExchangeApp As Object
    Set app = CreateObject("Acroexch.app")

    Dim filePaths As Collection     'Paths for PDFS to append
    Set filePaths = New Collection
    Dim fileRows As Collection      'Row numbers PDFs to append
    Set fileRows = New Collection
    Dim sourceDoc As Object
    Dim primaryDoc As Object        ' PrimaryDoc is what we append too
    Dim insertPoint As Long         ' PDFs will be appended after this page in the primary Doc
    Dim startPage As …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

5
推荐指数
1
解决办法
470
查看次数

将数据直接从Python导出到Tableau

我有一个将数据导出到csv中的python代码,然后将该csv加载到Tableau中。我不想将csv加载到tableau中。

有没有一种方法可以将return我的python脚本的值直接放入tableau中?

问题类似于使用JSON将数据从Python导出到Tableau中吗?,但他们询问Json格式,答案是使用csv。如果可能,我想跳过csv步骤。返回的数据将采用表格格式。

python tableau-api

5
推荐指数
1
解决办法
583
查看次数

Pandas Merge and filter

I used merge to create a dataframe between 2 of my query's. Now in the dataframe I want to put a filter on a column but I cannot get it to work. I am trying to add filter component date is null or blank.

    ##reading data from sql
    package = pd.read_sql(sql,con)
    component = pd.read_sql(sqla,con)

    ##doing the left join
    test2 = pd.merge(package,component, on = ['identifier','date'], how='left')

    ##shrinking the dataframe   
    test3 = test2[['identifier_x']].copy()
Run Code Online (Sandbox Code Playgroud)

i've tried doing the below but cannot get it …

python pandas

5
推荐指数
1
解决办法
530
查看次数

PostgreSQL ANSI、Python SQL、utf-8'编解码器无法解码字节 0xa0

我正在尝试在 python 中运行 sql 查询。在python 2中,这曾经有效,但现在我使用的是python 3,这不再有效。

我得到错误 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 1: invalid start byte

更新,在中间的3行中添加,也尝试使用'windows-1252'here。同样的错误:

conn_str = 'DSN=PostgreSQL30'
conn = pyodbc.connect('DSN=STACK_PROD')


###newly added
    conn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
    conn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
    conn.setencoding(encoding='utf-8')

sql = "select * from stackoverflow where p_date = " + business_date
print("Query: " + sql)
crsr = conn.execute(sql)
Run Code Online (Sandbox Code Playgroud)

追溯:

Traceback (most recent call last):

  File "<ipython-input-2-b6db3f5e859e>", line 1, in <module>
    runfile('//stack/overflow/create_extract_db_new.py', wdir='//stack/overflow')

  File "C:\Users\stack\AppData\Local\Continuum\anaconda3\anaconda3_32bit\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\stack\AppData\Local\Continuum\anaconda3\anaconda3_32bit\lib\site-packages\spyder_kernels\customize\spydercustomize.py", …
Run Code Online (Sandbox Code Playgroud)

postgresql pyodbc python-3.x

5
推荐指数
1
解决办法
1968
查看次数

熊猫,fillna / bfill联合和合并领域

我正在尝试在join_key中执行以下逻辑。 date + book + bdr + COALECSE(cusip,isin,deal,id)

+------------+------+------+-----------+--------------+------+------------+----------------------------+
|  endOfDay  | book | bdr  |   cusip   |     isin     | Deal |     Id     |          join_key          |
+------------+------+------+-----------+--------------+------+------------+----------------------------+
| 31/10/2019 |   15 | ITOR | 371494AM7 | US371494AM77 |  161 | 8013210731 | 20191031|15|ITOR|371494AM7 |
| 31/10/2019 |   15 | ITOR |           |              |      | 8011898573 | 20191031|15|ITOR|          |
| 31/10/2019 |   15 | ITOR |           |              |      | 8011898742 | 20191031|15|ITOR|          |
| 31/10/2019 |   15 | ITOR |           | …
Run Code Online (Sandbox Code Playgroud)

python pandas

5
推荐指数
1
解决办法
70
查看次数

将数组添加到一起(在VBA中)以进行输出

我可以将数组一起添加到输出中吗?

代码与标头匹配并将值返回到各种数组.当我尝试输出我的数组并将值一起添加时,我得到了

类型不匹配

在线

.Range("B" & lastrow + 1 & ":" & "H" & lastrow + 1).Value = Application.Transpose(R) + Application.Transpose(M) + Application.Transpose(O) + Application.Transpose(Q)
Run Code Online (Sandbox Code Playgroud)

在以下代码中:

Const FirstMatch As Boolean = True
Dim SR As Variant
Dim OAS As Variant
Dim iSR As Integer
Dim iOAS As Integer
Dim R As Variant
Dim M As Variant
Dim O As Variant
Dim Q As Variant
Dim headers As Variant
Dim iheaders As Integer

SR = Worksheets("Sheet A").Range("D3:J7").Value  ' Array for CS01 …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

3
推荐指数
1
解决办法
1380
查看次数