excel-vba

Replacing a value in a cell with another

岁酱吖の 提交于 2020-01-07 03:06:19
问题 I am writing a macro in Excel spreadsheets to replace a value in one cell by the content of another cell and loop through the original text replacing the same value, whenever it sees this word. For example, I have a text in a range of cells, where every line has a word "tagname" I want to replace "tagname" with the value of cell A1 of the same spreadsheet, for example to say "Maggie" instead of tagname. This is my code thus far: Private Sub CommandButton21_Click() Dim OriginalText As Range

Excel VBA Comparing between a given date and (given date - 2 months)

折月煮酒 提交于 2020-01-07 03:05:41
问题 I am writing a code to ensure that the data date of a system is not later than 2 business month-end date. For instance, if the job run date for the system is 23/12/2015, the valid data date is 30/10/2015 and 30/11/2015. The dates involved are only business days. I have this code below: If DateDiff("m", dataDate, jobRunDate) > 2 Then MsgBox "Error in dataDate" End If However, I do not know how to find: The last day of the month Compute 2 business month back Any help will be greatly appreciated

Find first non-blank cell for each column from rows that match lookup to merge duplicate matches

橙三吉。 提交于 2020-01-07 03:03:47
问题 I have a spreadsheet that is combined contact lists from a number of sources, with varying degrees of completeness. Some contacts have provided their information multiple times, but left different fields blank each time. I'm looking to remove at least some of the duplicates by combining rows to fill in the blank values. Here's a simplified example of what my data looks like id email phone company job title 01 johnsmith@example.com 5550123 acme inc 01 johnsmith@example.com acme inc CEO 02

Excel vba using variable as the name of ListObjects

邮差的信 提交于 2020-01-07 03:01:11
问题 Function update_avgcpu_data(Server_hostname) Dim rpt_name As String rpt_name = Server_hostname & "avgcpu" MsgBox rpt_name With ThisWorkbook.Sheets(Server_hostname).ListObjects.Add(SourceType:=0, Source:= _ "ODBC;DSN=localtest;",Destination:=ThisWorkbook.Sheets(Server_hostname).Range("$A$1")).QueryTable .CommandText = "SELECT cpu_avg_statistics_0.LOGDATE as 'Date of Month', cpu_avg_statistics_0.CPU as 'CPU Utilization %' FROM test.cpu_avg_statistics cpu_avg_statistics_0 WHERE (cpu_avg

Excel undo button

末鹿安然 提交于 2020-01-07 02:59:28
问题 When I change some value in my cell, the undo option is not available. Is it because I have vba programming code in background and how can I enable undo? Another question. When I try to save excel file it offers me xltm format. Since I don't have any macro (but i have vba code) i have saved it as xlsx. It looks that everything works for now, also vba code in background. What is the difference between xltm and xlsx format if there is any? 回答1: Are you changing the cell value using code?

Lookup multiple values in a single cell (separated by commas) and then return the values to a single cell (also comma separated)

给你一囗甜甜゛ 提交于 2020-01-07 02:57:05
问题 I need to Vlookup on column A of sheet1 with cell A1, A2 values SD-121, SD-232, SD-23 SD-323,SD-333 and so on.. vLookup table in a different sheet with column A, B, C, D. Column A having A B SD-232 US SD-23 UK SD-323 IN SD-333 SG SD-121 CN The lookup result is to be displayed in Column B of sheet1 result cell B1 and B2 B CN, US, UK IN, SG 回答1: You can create a user function to loop the values through the VLOOKUP function: Function VLOOKUPARRAY(ByVal lookup_val As Range, ByVal table_array As

Copy part of cells that varies in both length and content using VBA

风格不统一 提交于 2020-01-07 02:56:05
问题 So I have workbook1 (wbThis) and workbook2 (wbTarget) and in wbThis' sheet I have some cells which are filled. These cells have the format of: From A6 P2123: Begin procedure A7 P1234: Code A8 P4456-6: Document | V (down arrow) A27 It continues like that. Now I have 2 issues. Problem1 I want to copy the PXXXxX: (small x is like an arbitrary summation of - or _ or > etc etc) codes to wbTarget. This code varies as you can see but there will always be a "P" in the beginning and a ":" at the end.

Getting ActiveX component cant create object while trying to connect to ALM through VB macro

社会主义新天地 提交于 2020-01-07 02:53:27
问题 Getting ActiveX component cant create object error While debuuging the line - Set QCConn = CreateObject("TDApiOle80.TDConnection") 回答1: You must be using 64 Bit Excel. When ALM try to create OTA object(32 bit dll) in a 64 bit excel you will be produced with this error. Try the same code in 32 Bit Excel it will work smooth. Note : Please register both Clint and Site admin registration and dont forget to add the References. 来源: https://stackoverflow.com/questions/40420064/getting-activex

Code to Loop Through the COntrols of Userform and Prompt if any field is empty

你离开我真会死。 提交于 2020-01-07 02:51:09
问题 I have a userform whose image is attached below. What i need is when i press the submit button, it should promptv if there is any textbox left empty in the userform. Here is my code: Private Sub CommandButton1_Click() Dim intTextBox As Integer For intTextBox = 1 To 2 If Controls("TextBox" & intTextBox) = "" Then MsgBox ("TextBox" & intTextBox & "blank. Please enter relevant data!") Exit For End If Next intTextBox End Sub I am getting error at If Controls("TextBox" & intTextBox) = "" Then as

Excel VBA iterate over all used cells and substitute their values

老子叫甜甜 提交于 2020-01-07 02:35:07
问题 This is my first time ever working with VBA and Excel and my problem is probably caused by a big lack of knowledge on my part. I have a one column list of city names ( containing 800 items, hence I'm looking to automatically replace them ) and some chunks of text in which the term "cityname" occurs multiple times and needs to be replaced by the correct city name, which in my setup would be the value of the first column cell in the same row . So I found this: How to iterate through all the