I have developed a dependent dropdown sheet. For example when user selects option in cell B2 then further options from C2:L2 are provided.
Now i interested that if any dropdown i.e. B2:E2 are changed than next cells should automatically clear content. I want to do this for all rows independently. I have written this code in VBA however since I have large amount of rows it is difficult
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
Range("C2:L2").ClearContents
End If
If Not Intersect(Target, Range("B3")) Is Nothing Then
Range("C3:L3").ClearContents
End If
End Sub
Kindly recommend an alternative solution to do it without too many lines.
Related
Sorry for the basic question as I'm very new to VBA (day 1). I am trying to create a module which does the following:
You start the module by double clicking column A of the row you want to copy (active row).
The whole of the active row is copied.
A new row is added below the active row (same sheet).
All data in the active row is copied to this new row.
I would also like when you click the cell in column A for a Message box to pop up asking "Would like to copy the data to the row below?" (Yes/No).
I found some code online which allowed me to create the message box when clicking in column A. This seems to work really well and I am happy with this code. But this forum answer only allowed me to copy data from certain columns, not all columns in the active row.
I then found another forum post which did copy the full active row into the row below, and I combined the codes to get the following:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column > 1 Then Exit Sub
Cancel = True
If MsgBox("Do you want to insert a new row below this row?", vbYesNo) = vbYes Then
With Target
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
End If
End Sub
However, when try double clicking in column A, it seems like the original code is still running and its still only copying some of the columns data, not all columns. I'm not sure what I'm missing or if I am using the wrong code to copy the row to the row below.
Any help is appreciated.
I have one table of data (A) with data values, and a second table (B) which serves as a key that categorises/groups those entries into categories.
I am trying to write a cell formula that will list the category that corresponds to the data value in (A).
Some of the entries in the data table are empty, i.e. have no input data.
Case in point:
A13 has an empty cell, according to table (B), I specifically want the blank cell to be categorised as "Other". At the moment the sheet thinks cells like these are "null" and not "blank" and therefore returns #N/A.
I have tried adding an IFERROR function, which works at this stage but does not suit the scenario where a new data entry is entered as that will initially show as "Other" too when it should be something else, so I want to avoid using:
=IFERROR(INDEX(D2:D13,MATCH(A2:A13,E2:E13,0)),"Other")
Current cell formula for col B:
=INDEX(D2:D13,MATCH(A2:A13,E2:E13,0))
Please can you help? I've found plenty of articles on how to ignore blank/empty cells, but nothing to include them.
Many thanks!
OH
Shared link of problem
Screenshot of problem
use ifna like:
=IFNA(INDEX(D2:D13, MATCH(A2:A13, E2:E13, 0)))
update:
=INDEX(IF(A2:A13="",,IFERROR(INDEX(D2:D13,MATCH(A2:A13,E2:E13,0)),"Other")))
Currently using APEX 5.1.4
My goal is to have the user press a button, which triggers a new row to be added to the bottom of the IG. This row would also need to have some default values pre-populated, such as the sequence column I have functioning as a primary key.
Doesn't matter how exactly, but I was considering doing it with Javascript. However, none of the methods I have found online, regarding adding a row with Javascript, work.
Also, I have the header bar of the IG removed, so finding the native Add Row Button probably is not an option.
--EDIT--
I found some Javascript that successfully allows me to add a row, however, it adds the row directly underneath the currently selected row. I do not see any methods to automatically select the last row of the IG, and it still doesn't solve that the row needs to have some dynamic values upon instantiation.
Here is the javascript:
This shows all of the available functions that can be invoked ( with .invoke() ):
apex.region("id-region-emp").widget().interactiveGrid("getActions").list()
These following lines both instantiate a new empty row on the IG:
("row-add-row" adds to top of IG, "insert-record" adds underneath currently selected row.)
apex.region("id-region-emp").widget().interactiveGrid("getActions").invoke("row-add-row")
apex.region("id-region-emp").widget().interactiveGrid("getActions").invoke("insert-record")
Better to use below code:
apex.region("detaildataset").widget().interactiveGrid("getActions").invoke("selection-add-row");
Before applying this code make interactiveGrid editable by clicking on attributes and also apply primary key on one column and then apply this code in Execute javascript code:
apex
.region("detaildataset")
.widget()
.interactiveGrid("getActions")
.invoke("selection-add-row");
I am creating an excel sheet with following Data Validation drop down list.
NA
Done
(add some formula here)
Basically, i will be able to select either plain text "NA"/ "Done" from the dropdown list. But sometimes, I want the user to be able to calculate some values based on the cell respective to the row selected so, I want to have one formula as a choice inside the data validation dropdown list. Is this possible?
Data Validation List Source
When I click on Formulae option, it should execute the formula with respect to the cells in that Row
But currently, the formula that i put in doesn't execute, instead it will just show the whole formula in the cell when activated.
1)How can i make it so that when i select the formula from data validation list, it will execute it instead of filling up the cell with it?
2)How do i set the formula so that it will be using the cell from the current Row? (for example, if i am using the data validation List in N60, the formula should adapt itself to use the cell (let's say A60?).
I may not be able to help with the second part, but I was seeking an answer to the first and discovered a solution/workaround using Name Manager.
First, in Formula > Name Manager, create a new reference (the "refers to" will contain whatever formula you are wishing to ultimately display in the validation list. For this example, we use the formula reference "=IF($H54=..." and Name it "UniqueName"
Now, we go into Data Validation, Select List, and input the three items we want displayed in the list, with an equals sign preceding our newly named reference: ie. "NA,Done,=UniqueName"
Note: You can't start with the =UniqueName or validation will try to read it all as a formula and fail.
This method will allow the user to display "NA", "Done", or "=UniqueName" in the cell; if "=UniqueName" is selected, the cell itself will interpret this as a formula and execute it accordingly, displaying the results of "=IF($H54=...", or whateverelse you have designated to use as a named formula.
If it's too late for yours, I hope this helps someone else who may face a similar problem.
While I think I know what you're trying to say. Why don't you just use an IF formula to evaluate everything instead of selecting a drop down for every row manually. You already had it partially solved using IF. Just need to add the criteria for a "Done" and an "NA"
=if(A1="date","Done",if(A1<"date","NA",if(something else until you have all your catergories))
Just going to piggyback off of Mark's response.
If you really needed your named formula to be the first selection in the list, you can setup your list with a leading comma like so:
,=UniqueName,NA,Done
That worked out for my use, and there was no null item listed in the Data Validation drop down. Hope that helps!
How do i group columns using Excel interop?
if i record a macro (usually a good way to get started) i get this code:
Columns("I:M").Select
Selection.Columns.Group
unfortunately this doesn't work due to several problems, at least in C++. First of all, Application.Selection returns a normal Range, then Range.Columns is another Range. And Range.Group is this method:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.group%28v=office.11%29.aspx
This method only works in connection with pivot tables.
So how do i create a column group using Excel interop?
Even if i manage to create a group, how can i shrink/expand it? By that i mean clicking on the + to show the content of the group, or rather the other way around, "click" on the minus to hide the group. If i do that while recording a macro, it is not reflected in the macro at all.
Despite the fact that the Range.Group() documentation appears to relate to pivot tables, if you extract the columns using Range.Columns, and then apply the .Group() method to that range, it will have the desired effect. In C#:
Range range = sheet.get_Range("c1","e1");
range.Columns.Group();
Edit: The complete example, again in C# (apologies, it's the example I have handy):
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
app.Workbooks.Add();
Worksheet sheet = app.Workbooks[1].Sheets[1];
Range range = sheet.get_Range("c1","e1");
range.Columns.Group();
One thing the macro recorder obscures is the need to use the Range.EntireColumn property. Here's some code that groups, expands and collapses. I got this by googling and fooling around, but I think it gets the concepts right. Hopefully it's easy to translate into C++:
Sub test()
Dim ws As Excel.Worksheet
Set ws = ActiveSheet
With ws
If .Columns.OutlineLevel > 1 Then
'clear any existing hidden grouped columns and grouping
.Outline.ShowLevels columnlevels:=.Columns.OutlineLevel
.Range("1:1").EntireColumn.Ungroup
End If
'group
.Range("A:C").EntireColumn.Group
'collapse
ws.Outline.ShowLevels columnlevels:=1
'expand
ws.Outline.ShowLevels columnlevels:=.Columns.OutlineLevel
End With
End Sub