excel-vba

how to write a vba code to remove and replace UTF8-Characters

狂风中的少年 提交于 2020-01-03 17:18:04
问题 I have this code and I still can't seem to replace non English characters like Vietnamese or Thai from my data with a simple "placeholder". Sub NonLatin() Dim cell As Range For Each cell In Range("A1", Cells(Rows.Count, "A").End(xlUp)) s = cell.Value For i = 1 To Len(s) If Mid(s, i, 1) Like "[!A-Za-z0-9@#$%^&* * ]" Then cell.Value = "placeholder" Next Next End Sub Appreciate your help 回答1: You can replace any chars that are out of e. g. ASCII range (first 128 chars) with placeholder using the

Method 'VBE' of object '_Application' failed

为君一笑 提交于 2020-01-03 17:09:44
问题 One of my clients has issue running the Excel VBA code below. He gets the following error Method 'VBE' of object '_Application' failed , but only once, after he opens the VBE, it starts to work. Also, it was working for him until yesterday. He is using Excel 2010. This is the code that throws the error. For Each f In Application.VBE.ActiveVBProject.VBComponents If InStr(1, f.Name, "UserForm") = 1 Then Application.VBE.ActiveVBProject.VBComponents.Remove (f) End If Next f 回答1: You'll need to

Rounding Date and Time in VBA

拜拜、爱过 提交于 2020-01-03 16:13:29
问题 How can I round off date and time in excel using VBA? For example, the user selects the value from the calendar which is copied in Cell A6 = "08/25/2016 09:02:00" I am pulling the data in 15 minutes interval so I want it to be A6 = "08/25/2016 09:00:00" So if the user selects any date and time that is not in multiple of 15 minutes, it should go back to the previous 15 minute interval value and pull the data. 回答1: Pull out the minutes, floor the date portion to get rid of the time, then add it

Unable to set the Visible property of the PivotItem class (VBA)

允我心安 提交于 2020-01-03 15:56:54
问题 I am trying to manipulate an Excel 2007 Pivot Table trough VBA so I can loop trough the categories of the pivot table, set all to invisible but one, save the sheet as pdf and continue to the next category. For this I use the following piece of code. Dim pf As PivotField Set pf = ActiveSheet.PivotTables("PivotTable1").PivotFields("NAME") Dim pi as PivotItem For Each pi In pf.PivotItems If pi.Visible = False Then pi.Visible = True 'Error here End If Dim pi2 As PivotItem For Each pi2 In pf

How to hide columns in a ComboBox dropdown?

北慕城南 提交于 2020-01-03 15:55:23
问题 I'm building a ComboBox in an Excel userform that gets its rows from an Access table. I want to display several text fields to the user in the dropdown, but the value returned from the ComboBox should be the ID number associated with the row that the user selects (i.e. the ID column is the bound column). But I don't want to show this ID number to the user. Is there a way to hide a column in the ComboBox's dropdown, but still have that column be bound? 回答1: If you have three columns - the

Ink Tools - VBA - Excel Digital Signature/Drawing

萝らか妹 提交于 2020-01-03 15:24:08
问题 I wanted to add a handwritten digital signature in some of my companies forms. The goal is pretty straight forward, select a document, add a signature (through the use of a drawing pad, which can be done with Excel's Ink Tools ) and store the file in the server as PDF. This would cut out the necessity of printing and then scanning the form back in just to obtain a signature. I'm using excel for the main interface for file manipulation and search,but unfortunately I've not been able to find

Avoiding the use of Activate and Select when working with charts (Excel)

蓝咒 提交于 2020-01-03 14:22:07
问题 I know that using Activate and Select in Excel VBA is not best practice. I've seen references on how to avoid them when dealing with Ranges (example: LINK). How can I avoid them when dealing with ChartObjects (or anything other than Ranges, in general)? For instance, a way to modify the maximum value on the y-axis using Activate and Select would look something like this (which works): ActiveSheet.ChartObjects("MyChart").Activate ActiveChart.Axes(xlValue).Select ActiveChart.Axes(xlValue)

“New” Excel.Application vs Excel.Application

风格不统一 提交于 2020-01-03 12:23:34
问题 I am seeking clarification on the impact of "New" on the objects and the script. My understanding is that if I need to perform actions on an excel document and the application is closed then I should use New Excel.Application. If I keep this application active (through an object such as a Workbook for example) and later in the script I decide to open another workbook, should I still use New Excel.Application or would it be better to use Excel.Application then? My concern lies in the fact that

How can I get the length of the longest string in a column (Excel)?

ⅰ亾dé卋堺 提交于 2020-01-03 09:03:15
问题 I have an Excel spreadsheet that I am writing out to a file. I am currently using the following method to reproduce the contents of each cell: cell_contents = Right(Space(10) & Trim(Cells(iRow, iColumn)), 10) However, if the contents of the cell are longer than 10 characters long (or however long I choose to specify), then I loose parts of the data. Is there a way to quickly and easily get the length of the longest string in a range of cells? I have seen people suggest using the following

How can I get the length of the longest string in a column (Excel)?

强颜欢笑 提交于 2020-01-03 09:02:09
问题 I have an Excel spreadsheet that I am writing out to a file. I am currently using the following method to reproduce the contents of each cell: cell_contents = Right(Space(10) & Trim(Cells(iRow, iColumn)), 10) However, if the contents of the cell are longer than 10 characters long (or however long I choose to specify), then I loose parts of the data. Is there a way to quickly and easily get the length of the longest string in a range of cells? I have seen people suggest using the following