excel-vba

browse button in input box to find file Excel2007 Vba

浪尽此生 提交于 2020-01-05 05:40:26
问题 I need the browse button in input box to find file - VB A - EXCEL Macro][1] need to find the folder path via browse button instead of typing in input box is it possible? |-------------------| |-------------------| Browse by clicking a cell it should ask for file browse. should not be edited manually. i mean , i want to lock the particular cell locked. and only able to edit via macro. 回答1: Alternately: Sub tgr() Dim strFilePath As String strFilePath = Application.GetOpenFilename If strFilePath

Excel VBA - Auto FIlter and Advanced filter usage error

主宰稳场 提交于 2020-01-05 05:40:10
问题 I have a requirement where in, I need to use the auto filter to filter the data first and then am using the advanced filter to get the Unique values alone. But the advanced filter doesn't take the auto filtered value alone. How do I use them together? Here goes my code, Colmz = WorksheetFunction.Match("RSDate", Sheets("RS_Report").Rows(1), 0) ActiveSheet.ListObjects("RS").Range.AutoFilter Field:=Colmz, Criteria1:="YES" ActiveSheet.Range("B1:B65536").AdvancedFilter Action:=xlFilterCopy,

How to create a VBA formula that takes value and format from source cell

我与影子孤独终老i 提交于 2020-01-05 05:31:10
问题 In Excel's VBA I want to create a formula which both takes the value from the source cell and the format. Currently I have: Function formEq(cellRefd As Range) As Variant 'thisBackCol = cellRefd.Interior.Color 'With Application.Caller ' .Interior.Color = thisBackCol 'End With formEq = cellRefd.Value End Function` This returns the current value of the cell. The parts that I have commented out return a #VALUE error in the cell. When uncommented it seems the colour of the reference is saved

Save each worksheet in workbook as an individual pdf

亡梦爱人 提交于 2020-01-05 05:30:10
问题 I want to loop over all worksheets in a workbook and save them as individual pdfs in the same path as the workbook. The files are named after the worksheet name. This code below works up until the "wsA.ExportAsFixedFort" line. The error message i get is: Run-time error '91': Object variable or With block variable not set But i cant figure out what the issue is... Any suggestions? Option Explicit Sub WorksheetLoop() Dim wsA As Worksheet Dim wbA As Workbook Dim strTime As String Dim strName As

Tan() Returns Wrong Value

给你一囗甜甜゛ 提交于 2020-01-05 04:55:21
问题 I am trying to calculate angle between three points and I need to use the Tangent function tan() . The weird thing is that VBA return wrong value. for example: tan(209) = 0.554309051 but in VBA: tan(209) = -.696695985548265 My friend told me about something called "Normalize". but I didn't understand what he's talking about and how to do it. Why is this happening? 回答1: According to this VBA uses radians. Convert degrees into radians , ( degrees * 2 * pi) / 360 tan((209 * 2 * 3.14)/360) 回答2:

VBA code to auto select previous 10 columns

狂风中的少年 提交于 2020-01-05 04:55:17
问题 Referring from my previous question. VBA code to add current date in next cell How do I select the previous ten days data from current date entry. Example :As per my first screenshot Lets say i get the today entry will be on Column E and I want to select previous 10 entries to create a graph. So, if I come tomo, my entry will be on F and I want to select column F,E,D,C,,,, 回答1: Keeping you previous code from link, try this (untested): edited after OPs clarifications Option Explicit Sub Update

Tan() Returns Wrong Value

余生颓废 提交于 2020-01-05 04:55:13
问题 I am trying to calculate angle between three points and I need to use the Tangent function tan() . The weird thing is that VBA return wrong value. for example: tan(209) = 0.554309051 but in VBA: tan(209) = -.696695985548265 My friend told me about something called "Normalize". but I didn't understand what he's talking about and how to do it. Why is this happening? 回答1: According to this VBA uses radians. Convert degrees into radians , ( degrees * 2 * pi) / 360 tan((209 * 2 * 3.14)/360) 回答2:

Call same SUB from multiple buttons in VBA

喜夏-厌秋 提交于 2020-01-05 04:49:53
问题 I have multiple buttons (active x) on a spreadhseet in same column but different rows. These buttons capture the start time of an activity. If button 1 is pressed cell next to it should be populated by current time. If button 2 is pressed cell next to it should be populated by current time. and so on..... I have written a SUB in VBA as follows: Private Sub StartTimer_Click() Range("I4").Value = Now End Sub I do not want to repeat this code for each button action. Please let me know how it can

use variable in excel formula

余生颓废 提交于 2020-01-05 04:37:08
问题 I'm trying to make an automated sum based on an increasing number of rows. Here is my sample of code but I'm stuck as I don't know the syntax to include a variable in the formula of a cell. Sheets("Orderboek").Select Range("H" & (rOi + 1)).FormulaR1C1 = "=Sum(H3:H"&rOi&")" My variables are declared as follows: Dim i As Integer, a As Range 'i= index a een gebied Dim prText As String 'product text Dim rOi As Long 'rij nummer in orderboek Dim rng, sumrng As Excel.Range Dim r As Long 'rij number

Converting a column of UK dates to text in VBA

血红的双手。 提交于 2020-01-05 04:35:13
问题 My system is in a UK locale (windows 7, office professional Plus 2013). I have some columns of dates, stored as dates in the Uk format (dd/mm/yyyy) and I need to convert them to text in the same format. The problem i'm having is it seems that every VBA function defaults to spitting out US format dates when converting to text. I've tried using the range.TextToColumns function and example code is below (mostly macro recorder based - oddly text to columns works fine in excel, but the recorded