Posts

Showing posts with the label vba

object variable not set: for loops

object variable not set: for loops I really need quite a bit of help on this so I would really appreciate if you bear with me. I am new to VBA and hence I am facing difficulties running the code. It keeps returning me the error: object variable not set. May I know what is wrong with the code? Thanks in advance for your help! Sub sub_input (dicDat as Dictionary) Dim ws As Worksheet: Set ws =ActiveSheet Dim i As Integer Dim j As Integer Dim vTemp As Variant Range("rInputStart").Parent.Calculate vTemp =Range(Range("rInputStart").Offset(1),_ Range("rInputStart").End(xlDown).Offset(0,2)).value Dim info as string Dim currency As String: currency = vbNullString Dim exchangeRate as String: exchangeRate = vbNullString Dim remark as String: remark = vbNullString For j =1 To 10 info= "info" & CStr(j) info = Range("rInfoManual").value currency= "dl_currency" & CStr(j) exchangeRate = "exchange" ...

Conditional SUM within VBA

Image
Conditional SUM within VBA Large excel data which looks like this: Now I have to create a macro for my data to filter. The filtration process is as follows: First select the operator = mum and then select price as 1 and get sum of count column and then 2 and get sum of count column and so on.... then select operator = delhi and similarly select price as 1 and get sum of count column and then 2 and get sum of count column and so on Record Macro then generalise and optimise. – PatricK Jul 2 at 6:09 1 Answer 1 For mum , =sumifs(c:c, d:d, 1, f:f, "mum") =sumifs(c:c, d:d, 2, f:f, "mum") =sumifs(c:c, d:d, 3, f:f, "mum") ... For dehli , =sumifs(c:c, d:d, 1, f:f, "dehli") =sumifs(c:c, d:d, 2, f:f, "dehli") =sumif...

VBA IE 10 Automation - Automatically Save PDFs

Image
VBA IE 10 Automation - Automatically Save PDFs I'm trying to automate the process of saving PDF invoices for bookkeeping purposes. The method suggested here does not work because a login is required to access the invoices. PDF I currently have a macro that navigates to the page, logs in and opens the links to each invoice. The URL scheme for these invoices is .../account/invoice/?invoice_number=XXXXXX . Navigating to each of these URL brings up the files in the URL .../account/invoice/?invoice_number=XXXXXX URL window. I would like the files to automatically save, but according to this page, the Always ask before opening this type of file option was depreciated from IE 10 and 11 due to security reasons. Always ask before opening this type of file I attempted to automatically click Save using this method, but the code here seems to be for a different version of IE. Save The line: hWnd = FindWindow("#32770", "File Download") was modified to: hwnd = FindWindow...

VBA: Copy row from SourceSheet and paste into DestSheet using dynamic rows

VBA: Copy row from SourceSheet and paste into DestSheet using dynamic rows I'd like to copy area from another workbook. SOURCE: The area starts from J15 to last row of J column. I'm having trouble with the syntax. DESTINATION: The area where the paste is the same area as in the Sourceworkbook, but K Column (K15 to last row of J column) The problem is the with statement. I keep getting this error: https://pasteboard.co/HsxMzPZ.jpg Picture of the sourcesheet for clarification https://pasteboard.co/Hs8gDsF.jpg Public Sub Subledger_Makro() Dim Subwb As Workbook Dim Subsht As Worksheet Dim Sourcewb As Workbook Dim SourceSht As Worksheet Set Subwb = ActiveWorkbook Set Subsht = Subwb.Sheets("SAPBW_DOWNLOAD") SourceFile = Application.GetOpenFilename(, , "Open yesterdays Subledger Report") Set Sourcewb = Workbooks.Open(SourceFile) Set SourceSht = Sourcewb.Sheets("SAPBW_DOWNLOAD") 'Copies the previous day Subledger (SourceSht) report J-Column to new the ...

Web scrapping of masked URL using VBA

Image
Web scrapping of masked URL using VBA I want to scrape some stock data from a website https://dps.psx.com.pk/ using VBA in Excel, but the problem is the URL of this website does not change. When I click on market summary as highlighted in the below image that will return the whole market summary, I just need to scrape data in Excel using VBA as highlighted in the following image: Did you look at the requests being made when you search for "EFOODS"? – antfuentes87 Jul 1 at 16:30 This is basic web scraping. You need to inspect the source code elements and like @antfuentes87 says , follow the requests. It sounds more like you need to purchase a third party tool to help you. It's also called "scrape" and "scraping" – dbmitch Jul 1 at 16:44 ...

copy single row from multiple worksheets into new worksheet

Image
copy single row from multiple worksheets into new worksheet I'm not a developer, but was recently hired for a newly created position, meaning I'm trying to create reports and things from scratch that have never been done before. The IT department doesn't have time to teach me and so I'm trying to learn VBA and Access and other advanced data analysis tools, but I don't understand how to write code to the extent I need it yet. I used several things from these forums, but I've been lucky enough to mostly copy and paste to get what I need. I copied this from this forum (second answer): copy the same row from multiple sheets into one sheet in excel This is the code I copied: Sub copyrow() Dim Nrow As Long, Nsheet As Long Dim i As Long Nrow = 7 Nsheet = 6 For i = 1 To Nsheet - 1 Sheets(i).Cells(Nrow, 1).EntireRow.Copy Sheets(Nsheet).Cells(i, 1) Next i End Sub I tested it and it worked, but I didn't realize that Nsheet meant it would go to the 6th sheet and rep...

Run time error '5': while using global variables

Run time error '5': while using global variables i declared the global variable in the Module1 and when i was trying to use it in another module it is showing the runtime error '5':invalid procedure call or argument. i was unable to find the problem please provied the solution for this problem Declaring global variable: Function getFilePath() As String getFilePath = FilePath Set FilePath = "C:quadysterR3AgreementDetails" End Function Implementing of globalvariable: Private Sub SendAgreement_Click() If (Not IsNull(Me.RequestFrom) And Not IsNull(Me.RequestReference)) Then Call AttachR3ServiceAgreement(Module1.FilePath, tripObjectFormation, "Agreement") Me.AgreementDate = Now() Else MsgBox "Please provide 'RequestFrom' and 'RequestReference' to proceed." & vbNewLine & vbNewLine & _ "Press Ok to continue.", vbOKOnly, "Alert!!!" End If End Sub this is the calling function Public F...

EXCEL VBA: getting the integer value of mm in today's date

EXCEL VBA: getting the integer value of mm in today's date novice programmer here and it's my first question here. I'm interested in doing some invoicing using excel, and a part of that is generating invoice numbers, e.g. 1870001-1879999, referring to the year 2018, the month of July, and the 1st to 9999th invoice of this month. To do this, I've written a bit of code: Private Sub Workbook_Open() Dim MValue As String Dim XValue As Integer MValue = Format(Date, "mm/dd/yy") LValue = Left(MValue, 2) XValue = CInt(LValue) Range("K1").Value = XValue End Sub This would give me "7" as an integer in the cell K1, which I can then multiply by 10000 and add to 1800000 to give the baseline value of 1870000. I have two questions: 1) what's a better way to do this problem? My method seems incredibly long. (dates are stored awkwardly in excel) 2) why is it that: Range("K1").Value = XValue * 10000 causes an error? Thanks. ...

For loop in VBA when refreshing Bloomberg requests

For loop in VBA when refreshing Bloomberg requests I am putting together an excel workbook that performs various calculations based on a number of Bloomberg fields. For a particular date, it checks various requirements and then outputs either a 1 or -1 in a row based on if the requirements are met or not. I have got this working with a macro. The issue is I need to run the checks through a number of dates. So each loop I need the input date to be changed, the Bloomberg data needs to refresh and then either put a 1 or -1 in the next row down based on if requirements are met for this date. The problem is I can not get the loop to work correctly. Below is a simplified version of my code: Public i As Integer Public Sub RefreshStaticLinks() Call Worksheets("Sheet2").Range("A5:H7").Select Call Application.Run("RefreshCurrentSelection") Call Application.OnTime(Now + TimeValue("00:00:10"), "ProcessData") End Sub Private Sub ProcessD...