vba

Unique range in Excel doesn't return the unique record but all other records

牧云@^-^@ 提交于 2021-02-11 15:42:12
问题 I have got a problem with the unique value in Excel. I used the advice from this query: Extract unique value from the range in Excel used the following module: Public Function unikue(rng As Range) Dim arr, c As Collection, r As Range Dim nCall As Long, nColl As Long Dim i As Long Set c = New Collection nCall = Application.Caller.Count On Error Resume Next For Each r In rng c.Add r.Text, CStr(r.Text) Next r On Error GoTo 0 nColl = c.Count If nCall > nColl Then ReDim arr(1 To nCall, 1 To 1) For

How to select the first visible row after applying a filter

僤鯓⒐⒋嵵緔 提交于 2021-02-11 15:35:25
问题 I'm filtering a table in Excel but I only want the first line that appears. 回答1: Use Range.SpecialCells method with the xlCellTypeVisible parameter on the filtered range. .Rows(1).Cells should be what you want. Sub first_row() Dim rFirstFilteredRow As Range With Worksheets("Sheet1") With .Cells(1, 1).CurrentRegion 'do all the .autofilter stuff here With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0) If CBool(Application.Subtotal(103, .Cells)) Then Set rFirstFilteredRow = _

how to write an if statement code to compare two cell's value in one sheet to another cell in another sheet

孤街浪徒 提交于 2021-02-11 15:35:14
问题 i have two columns (Start Date, End Date) and i want a code that changes the color of both their cells to red if the start date and end date contained any date located in another sheet I tried using conditional formatting using this rule: =AND(C2<=Holidays!$A$2:$A$15,D2>=Holidays!$A$2:$A$15) 回答1: Tested out the below formula for myself and think it should work! Effectively rather than a simple AND statement, since we're comparing against an array of values rather than single cells, we need to

How to select the first visible row after applying a filter

邮差的信 提交于 2021-02-11 15:35:00
问题 I'm filtering a table in Excel but I only want the first line that appears. 回答1: Use Range.SpecialCells method with the xlCellTypeVisible parameter on the filtered range. .Rows(1).Cells should be what you want. Sub first_row() Dim rFirstFilteredRow As Range With Worksheets("Sheet1") With .Cells(1, 1).CurrentRegion 'do all the .autofilter stuff here With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0) If CBool(Application.Subtotal(103, .Cells)) Then Set rFirstFilteredRow = _

how to write an if statement code to compare two cell's value in one sheet to another cell in another sheet

拈花ヽ惹草 提交于 2021-02-11 15:34:38
问题 i have two columns (Start Date, End Date) and i want a code that changes the color of both their cells to red if the start date and end date contained any date located in another sheet I tried using conditional formatting using this rule: =AND(C2<=Holidays!$A$2:$A$15,D2>=Holidays!$A$2:$A$15) 回答1: Tested out the below formula for myself and think it should work! Effectively rather than a simple AND statement, since we're comparing against an array of values rather than single cells, we need to

how to write an if statement code to compare two cell's value in one sheet to another cell in another sheet

二次信任 提交于 2021-02-11 15:34:23
问题 i have two columns (Start Date, End Date) and i want a code that changes the color of both their cells to red if the start date and end date contained any date located in another sheet I tried using conditional formatting using this rule: =AND(C2<=Holidays!$A$2:$A$15,D2>=Holidays!$A$2:$A$15) 回答1: Tested out the below formula for myself and think it should work! Effectively rather than a simple AND statement, since we're comparing against an array of values rather than single cells, we need to

Converting Seconds to Years, days, hours, min, secs

[亡魂溺海] 提交于 2021-02-11 15:33:16
问题 I have this much to convert seconds to hours, minutes, and seconds. I need to make it work for years, and days too. Can someone help? Dim mHours As Long, mMinutes As Long, mSeconds As Long mSeconds = 12345 ' Sample data mHours = mSeconds \ 3600 mMinutes = (mSeconds - (mHours * 3600)) \ 60 mSeconds = mSeconds - ((mHours * 3600) + (mMinutes * 60)) MsgBox mHours & ":" & mMinutes & ":" & mSeconds 回答1: Thanks Everyone, I ended up using the Mod function. If (seconds >= 31536000) Then years =

What VBA event allows to capture click value of ActiveX combobox?

大兔子大兔子 提交于 2021-02-11 15:30:09
问题 After choosing item from ActiveX combobox by mouse click I would like the combobox to be closed and the item to be chosen. Here is an example. I have tried TempCombo_Click event but it is fired AFTER the TempCombo_Change event. And when I select item by click, my search string passed to TempCombo_Change event is empty. So I need something to preserve item selection in TempCombo_Change event. I use modification of VBA code taken from Autocomplete suggestion in Excel data validation list again

What VBA event allows to capture click value of ActiveX combobox?

北城以北 提交于 2021-02-11 15:28:24
问题 After choosing item from ActiveX combobox by mouse click I would like the combobox to be closed and the item to be chosen. Here is an example. I have tried TempCombo_Click event but it is fired AFTER the TempCombo_Change event. And when I select item by click, my search string passed to TempCombo_Change event is empty. So I need something to preserve item selection in TempCombo_Change event. I use modification of VBA code taken from Autocomplete suggestion in Excel data validation list again

Requery multiple instances of form independently in VBA (Access)

我的未来我决定 提交于 2021-02-11 15:24:50
问题 I am using Allen Browne's brilliant code (http://allenbrowne.com/ser-35.html) to open several instances of a form on click event. I understand that new instances are read-only and I managed to record the data the user inputs, to keep a log, thanks to this post (Access 2007 / VBA - Multiple Instances of Form, Update controls on specific instance from Module). I have several combo boxes on each form and would like to update/requery what is shown in one depending on user selection on other (for