excel-vba

Insert Excel Formula via VBA

倾然丶 夕夏残阳落幕 提交于 2020-01-30 10:36:07
问题 as a continuation from another question, I'm trying to solve my problems inserting a formula via VBA on a macro. Here's my code: Range("F1").Select ActiveCell.Formula = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))" For some reason, and the code doesn't show any errors, when I try to run it I get: Run-time error ("Application-defined or object-defined error") Worth mentioning I'm

Insert Excel Formula via VBA

≯℡__Kan透↙ 提交于 2020-01-30 10:35:32
问题 as a continuation from another question, I'm trying to solve my problems inserting a formula via VBA on a macro. Here's my code: Range("F1").Select ActiveCell.Formula = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))" For some reason, and the code doesn't show any errors, when I try to run it I get: Run-time error ("Application-defined or object-defined error") Worth mentioning I'm

Insert Excel Formula via VBA

孤街浪徒 提交于 2020-01-30 10:35:08
问题 as a continuation from another question, I'm trying to solve my problems inserting a formula via VBA on a macro. Here's my code: Range("F1").Select ActiveCell.Formula = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))" For some reason, and the code doesn't show any errors, when I try to run it I get: Run-time error ("Application-defined or object-defined error") Worth mentioning I'm

Get data out of a webpage with VBA

馋奶兔 提交于 2020-01-30 10:31:41
问题 I'm trying to get some data out of this Webpage: http://www.vodafone.de/privat/handys-tablets-tarife/smartphone-tarife.html I want to have the whole table on the right site for every Smartphone and every contract type. one time payment for Setting up: Anschlusspreis one time payment for the phone: Smartphone total amount: Gesamt Monthly payment for the contract: Basispreis Monthly payment for the mobile phone: Smartphone-Zuzahlung This is all stored in the JavaScript part which is a huge

Return VBA Network Drive Letter for Different Users

久未见 提交于 2020-01-30 08:37:06
问题 I've created a portal for myself and coworkers to download workbook templates that reference different network drives in an effort to consolidate. The portal is hosted in the "Accounting" (Z:/) drive, but one of the workbooks references a spreadsheet in a different drive "BI" (Y:/). This works splendidly on my machine, but my coworkers have different drive letters (e.g. M:/Accounting, U:/BI). Is there a way to search a network for a name and return the drive letter? Here's a rough

VBA — variable in .formula

你离开我真会死。 提交于 2020-01-30 08:27:27
问题 is there a more elegant (simpler) way to put a variable in .formula? I don't want to use .formulaR1C1 I have this code: Range("C8").Select Selection.End(xlDown).Select PosR = ActiveCell.Row KonR = PosR - 2 Range("N" & PosR).Select aAddress = Range("$N$9").Address & ":" & Range("$N$" & KonR).Address ActiveCell.Formula = "=SUM(" & aAddress & ")" Obviously I want to put =SUM($N$9:$N$101) (101 is the last cell minus 2) into that cell and this code does the job. But I just want to be sure that

Simple way to change a pivot cache

大城市里の小女人 提交于 2020-01-30 08:11:06
问题 This doesn't work... Sub changeData_Error() Dim pc As PivotCache Set pc = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Range("A1:B2")) Excel.Sheets("Sheet1").PivotTables("PivotTable1").ChangePivotCache pc ThisWorkbook.RefreshAll End Sub Have ended up with the following which seems over complicated. Can it be simplified? Sub changeData() ':: this is the table I'd like to change the data Dim mainP As PivotTable Set mainP = ThisWorkbook.Sheets("Sheet1").PivotTables(

Getting an Extra Empty line when exporting Excel Range to .txt file

删除回忆录丶 提交于 2020-01-30 07:42:08
问题 I am trying to copy an Excel range to a .txt file. The export is successful, with one exception, It adds one " extra " empty line at the end. I've read and tests many of the solution on SO (and other sites), but still without any success. My Code (relevant part) ' === Export to the .txt file === Dim TxtFileName As String, lineText As String TxtFileName = ThisWorkbook.Path & "\Inv_" & Format(Date, "yyyymmdd") & ".txt" Open TxtFileName For Output As #1 With StockSht For i = 1 To LastRow For j =

How to resize all images on a worksheet?

Deadly 提交于 2020-01-30 06:47:25
问题 I have several images on a worksheet. I want to resize them all to the same size, but I can't seem to get it working quite right. I thought it would be like the code below, but this actually makes everything different sizes. Sub ChangeAllPics() Dim s As Shape For Each s In ActiveSheet.Shapes s.Select s.Width = 500 s.Height = 200 Next s End Sub 回答1: I think you're only missing a minor thing. By default (when I test it) images inserted to the sheet have LockAspectRatio=True . You need to set

Trying to run a worksheet change event twice

柔情痞子 提交于 2020-01-30 06:25:39
问题 I am trying to run this worksheet change event for two different columns(A) and (I)... Private Sub Worksheet_Change(ByVal Target As Range) Dim A As Range, B As Range, Inte As Range, r As Range Set A = Range("A:A") Set Inte = Intersect(A, Target) If Inte Is Nothing Then Exit Sub Application.EnableEvents = False For Each r In Inte r.Offset(0, 1).Value = Date Next r Application.EnableEvents = True End Sub This event is something i found on this forum. Its purpose is to make it so whenever data