vba

How to pivot duplicate rows to columns?

*爱你&永不变心* 提交于 2021-01-29 18:30:30
问题 having a hard time figuring out how to pivot a multi-column data set with duplicate rows into unique columns. I have done research and found some VBA scripts to do this, but it is resulting in data missing when I do counts to confirm it pivoted correctly and ends up adding in duplicate columns (name/ rating year) over and over. Anyone have any ideas? I'd do a pivot table, but I can't display the actual rating values in a pivot, only a sum/count/avg. etc... 回答1: You can do this easily in

Capture visible values from filtered range from a particular column in an array

空扰寡人 提交于 2021-01-29 18:28:27
问题 Description : I have a sheet with about 30 columns and more than 500k rows on average (there are multiple files). Column 8 of the sheet holds filenames. I am applying filter on this column to only display rows with filenames that I want to see Goal : After applying the filter, I want to capture all visible rows in column 8 into an array. This is the bit I'm struggling with Code : Sub GetFilteredColumn() Dim oWS As Worksheet: Set oWS = ThisWorkbook.Worksheets("Sheet1") Dim iLRow As Long, iRow

ShiftVector not wrapped around-cells showing zeroes

♀尐吖头ヾ 提交于 2021-01-29 18:22:47
问题 I'm currently working on this vba programming question. Here's my code: Option Explicit Option Base 1 Function ShiftVector(rng As Range, n As Integer) As Variant Dim A() As Variant, B() As Variant Dim nr As Integer, i As Integer nr = rng.Rows.Count ReDim A(nr, 1) As Variant ReDim B(nr, 1) As Variant A = rng For i = 1 To nr - n If i <= (nr - n) Then B(i, 1) = A(i + n, 1) End If Next i For i = (nr - n + 1) To nr If i <= nr Then B(i, 1) = A(i - nr + n, 1) End If Next i ShiftVector = B End

Get the Nth index of an array in VBA

谁说我不能喝 提交于 2021-01-29 18:21:52
问题 I am a noob in VBA and can't find a way to get the element of an array at a given index... It might be easy for you, though. I have an excel file with 2 columns, "Emails" and "Categories", and I want to filter out all emails for a given category. I ended up so far with the following code: Sub filterEmails() Dim tbl As ListObject Dim emails As Variant Dim email As String Dim categories As Variant Dim category As String Dim i As Integer Set tbl = ActiveWorkbook.Worksheets("Feuil1").ListObjects(

Use VBA to tell Outlook to print to a specific printer

≡放荡痞女 提交于 2021-01-29 18:06:31
问题 Is there any way to write a VBA macro in Outlook that forces a printout to a specific printer (even if it's not necessarily the default printer), similar to the Word Application.ActivePrinter = "Printer Name" option? I'd like to create a button that prints the current email and attachments to a specific printer (in this case a PDF printer, but I'm guessing it should be the same principle regardless), but can't seem to find a way to force which printer is used in the code. Thanks. 回答1: No,

VBA code to know URL validity that will check whether URL is exist or not

你离开我真会死。 提交于 2021-01-29 17:49:01
问题 I have code to know the URL existence but in many other systems or may another office version it is not working. could please help me with this? Where is im doing wrong? Is there an alternate option? Thanks in advance I am using code to know URL VALIDITY is Public Function IsURLGood(URL As String) As Boolean Dim request As New WinHttpRequest On Error GoTo IsURLGoodError request.Open "HEAD", URL request.send If request.Status = 200 Then IsURLGood = True Else IsURLGood = False End If Exit

MS Outlook Explorer_Close Event

烈酒焚心 提交于 2021-01-29 17:31:22
问题 I have the following code: Option Explicit Public WithEvents myOlExp As Outlook.Explorer ' Initiation Private Sub Application_Startup() Set myOlExp = Application.ActiveExplorer End Sub ' Termination Private Sub myOlExp_Close() MsgBox "quit" End Sub The code itself works fine - with one important limitation (= my problem). The Explorer_Close event is only triggered when multiple Outlook windows are open and these are being closed. However when the last/main Outlook window is being closed, then

Excel VBA and HTML DOM: Can't Click Tab

无人久伴 提交于 2021-01-29 17:29:00
问题 In Excel 2003 VBA, I'm trying to browse to this web page... https://www.google.com/finance?q=NYSE%3AWSO&fstype=ii&ei=cy30UrCEI8KKiALOPw ...and click these two tabs on it: - "Balance Sheet" - "Annual Data" Here's what the HTML for those tabs looks like: <a class=t><b class=t><b class=t>Balance Sheet</b></b></a> and <a id=annual class="id-annual nac">Annual Data</a> Finding Annual Data with getElementById, and clicking on it, worked fine. But Balance Sheet has no ID. Using getElementByClass

Web scraping without specified name, id, or class attached to the data

一笑奈何 提交于 2021-01-29 17:27:24
问题 I am trying to track the status of shipping delivery and display it on an Excel tab. This website https://webcsw.ocs.co.jp/csw/ECSWG0201R00003P.do, displays data when the "Air wayBill No." is entered. I managed to open Internet Explorer, enter the Air WayBill number, then click the search button. Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Navigate "https://webcsw.ocs.co.jp/csw/ECSWG0201R00000P.do" IE.Visible = True While IE.busy DoEvents Wend Set document = IE

How to suppress error message after cancel report print?

时光总嘲笑我的痴心妄想 提交于 2021-01-29 17:15:34
问题 I used DoCmd.RunCommand acCmdPrint to print a report. If I print the report, ok. But if I cancel, Access show a error and stop run the button code. I used DoCmd.SetWarnings (False) but don't suppress this error. How can I do? 回答1: You need to check the error code in your error handler, and if it's "Operation cancelled", ignore it. Option Explicit Sub Something() On Error GoTo Trap 'DoCmd... Leave: On Error GoTo 0 Exit Sub Trap: If Err.Number <> 2501 Then MsgBox Err.Description, vbCritical