excel-vba

Excel VBA query for a closed workbook

南笙酒味 提交于 2020-01-03 02:40:09
问题 I've been trying to adapt excel VBA queries for retreiving data from a closed workbook as an alternative option. I found a sample code online and I adjusted it as I thought to fit my needs. After frusterating few hours I can't quite figure out why it will not work. When I try to specify a table I get the error "Microsoft access database engine cannot find the object 'CompanyInFo' ... I tried replacing it with a defined name range aswell and still receive the same error. Heres the Code: Sub

“entirerow.delete” skips entries in For loop

别来无恙 提交于 2020-01-03 02:32:06
问题 I'm trying to clean up a set of data and noticed something strange with vba function entirerow.delete The following code will, as intended, delete the entire row if it is in the format strikethrough, but will skip the rows immediately following it, if they are also in that format. It seems like a it takes a row that is not in the strikethrough format to "reset" the ability to delete more rows. Does anyone know why, or what I could do to debug this? For Each rng In rng1 'Check each character

Return in VBA, does not do what I expect

我只是一个虾纸丫 提交于 2020-01-03 02:29:10
问题 Public Function GetRowToWriteOn(ByVal SheetName As String, ByVal id As Integer) As Integer LastRow = ActiveSheet.UsedRange.Rows.Count myarray = Sheets(SheetName).Range("d7:d" & LastRow).Value For row = 1 To UBound(myarray, 1) If (myarray(row, 1) = id) Then Return row End If Next End Function The IDE says expected end of statement, how do I do what I want? (Return the row where id is the same?) I'm not familiar at all with VBA, but when I look this example from microsoft this should work? :

Find Match, Copy Row from Sheet1 and Insert Into Sheet2

孤者浪人 提交于 2020-01-03 02:28:29
问题 In Sheet1, I have around 10,000 rows representing different people. Each person has a unique ID located in column D, which is a number sequence stored as text. In Sheet2, I have around 1,200 person entries that have have a reference to a matching person in Sheet1 located in column A. This reference is the same unique ID used in Sheet1. What I would like is to have a macro do is this: read-in the value of cell A1 on Sheet2 find the matching value in column D on Sheet1 copy the matching row in

Excel VBA: How Check the Name of Picture Inside the Cell?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 02:27:54
问题 I'm writing a program in macro that will check the name of the picture in a cell, then put a value on the next column based on the name of the picture. My program only checks if the name of the picture exists in the activesheet. My goal is to check if the name of the picture is on this cell and then put a value on the next column based on the name of the picture. Thanks a lot. Sub CheckImageName() Dim iRowCountShapes As Integer Dim sFindShape As String iRowCountShapes = 2 While Sheets("Data")

Color Cell Based on Value in Cell

╄→尐↘猪︶ㄣ 提交于 2020-01-03 01:47:08
问题 Using a macro I have consolidated info from several workbooks into one sheet in new workbook. In one column I have created a named range called ColRange. That column has numbers ranging from -350 to 500. How do I change the color of the cells based on the value of the text in the cell. red(0-500) yellow(-5-0) green(-350--5) 回答1: Have a look at conditional formatting. You may not even need VBA to do this. That being said, the VBA code would look something like this: Public Sub colorit() Dim

Save the active open document as pdf file

↘锁芯ラ 提交于 2020-01-03 00:54:12
问题 I have the below code that copy range cell values from excel and paste as picture in a new word document. I want to save the active document as pdf file with name of file as value in cell "A2". If you can help me in adding the same in the below code it would be a great help. Sub Picture() Dim objWord, objDoc As Object ActiveWindow.View = xlNormalView Range("A2:K25").Select Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture Set objWord = CreateObject("Word.Application") Set objDoc =

Autofill the same number from column A in column B

牧云@^-^@ 提交于 2020-01-03 00:52:12
问题 I need to create output like the following: Column A | Column B 1. 1 1 2. 1 3. 2 2 4. 2 5. 2 So far, I have written the following code: Sub ItemNum() Dim rng As Range Dim i As Long Dim cell Set rng = Range("A1:A99") i = 1 For Each cell In rng If (...) Then cell.Offset(0, 1).Value = i End If Next End Sub I have already obtained the number sequence in column A. I need to add the same value in column B down to the column. I would like to know how to add to increment statement. Thanks 回答1: If

Clicking Table Row in HTML Table using VBA

无人久伴 提交于 2020-01-02 23:16:08
问题 I am attempting to create an automation tool in Excel using VBA which runs and downloads a database query from a website portal. The tool is almost completely functional, but the one step I just cannot figure out is the query selection. Once the user has searched for the query in the portal, applicable queries are put into rows within a HTML table. There are two ways a user can run a query: double-click a row OR click a row and then click another button in the portal. My difficulty is that I

Insert copied row based on cell value

帅比萌擦擦* 提交于 2020-01-02 23:09:13
问题 The vba code below (modified from here) will insert a blank row above any row that has a value of "0" in column E. Instead of inserting a blank row, is there a way to copy the row with "0" and insert it above itself? Can this vba code be modified to do this? Sub BlankLine() Dim Col As Variant Dim BlankRows As Long Dim LastRow As Long Dim R As Long Dim StartRow As Long Col = "E" StartRow = 1 BlankRows = 1 LastRow = Cells(Rows.Count, Col).End(xlUp).Row Application.ScreenUpdating = False With