I have an userform with a few texbox and i want that when you put the value on the first one scan the data sheet and if it found the same value it fill the rest of textboxes, i think i can manage to do it if i do it in two steps. First take the value of textbox1 as variable and with it scan the data an generate the second userform with the data already paste on it. But is there a way to do it live? at the moment i put data in textbox1 shows the data of the rest of the columns on the others textboxes?
Also i was trying to do more or less the same thing in a sheet with an vlookup formula (VLOOKUP(A27,BDD!A:B,2,FALSE)) and it worked but the problem is that i want the formula to change the value of the cells only in case it found a mach in the data and also i don't want the formula in the cells i want to change so i can put new data without problem.
Lets say i have in the sheet "bdd" numbers in the first columns and names in the second. I want in another sheet to put a number and if that number already exist in the bdd i want to have the name near to it but i dont want the formula near to the numbers because i want to be able to put new numbers and names if necessary.
bdd:
101 Antonio
102 Luis
sheet
101 Antonio (At the moment i finish writing 101)
103 Peter (nothing happens because it isn't in the bdd yet and i have to type peter to complete that line or put 103 peter in the bdd)
Sorry if it wasn't clear i tried :P Thanks in advance
If data is in this range
Private Sub TextBox1_Change()
'Skip if value is not there
On Error Resume Next
'take any random cell to store textbox1's value
Range("C4").Value = TextBox1.Text
'Vlookup to get the value
TextBox2.Text = Application.WorksheetFunction.VLookup(Range("C4").Value,Sheet1.Range("A:B"), 2, 0)
End Sub
Related
As you can see the , the column under "Aep cost" contains an if statement that matches the month to the month entered in C2 to extract values from "total bill" for the relevant bill. But I lose the values when the month in C2 is changed. I need to record the values into the L column in such a way that they retain those values and don't go back to 0 when the if statement under "aep cost" is not satisfied. They only change if the "total bill" amount changes. I hope the question is clear.
Firstly, remove the formulas in the range K12:K23. You can't use formulas here as they will update automatically. Leave the 2 d.p. formatting in place though.
The following macro (don't forget workbooks with macros need to be saved as .xlsm, not .xlsx!) will place the value found in K8 into the relevant cell of the K12:K23 table based on the month value in C2.
Sub update_AEP_cost_for_month()
Dim mth As Long, ttl_bill As Double
With ActiveSheet
mth = .Range("C2").Value
ttl_bill = .Range("K8").Value
.Range("K12:K23").Cells(mth).Value = ttl_bill
End With
End Sub
What you need to decide is how to trigger the running of this macro:
I'd probably suggest the simplest way would be to add a shape/button in the J4 area, label it 'Update' and have the user click it when the update should run.
An alternative would be to use a calculation event - but that might cause problems if K8 and C2 aren't always perfectly in sync.
Thank you in advance for your help.
The short version:
Need to have it so specific cells in a table are locked based on the what the first cell in that row contains.
The cell that is used to determine if other cells in the row are locked needs to always remain unlocked
I am working on an Excel sheet that contains a table. This table is used to record key information about products and is being updated daily. Each product is defined in its own row with columns being used to show details such as "Drawing number" and "Customer" etc.
Depending on the stage the product is at in development and how well the product went once completed, it will be labeled with a single "state" from a list such as "Ongoing", "Bad-product", "Archived" etc.
enter image description here
In each cell in each row, the text the cell contains is determined through either data validation in the form of lists or manually typed in. for example, all cells in the customer column will use a dropdown menu to select a customer from a list, but the cells in the drawing number column are always one of a kind so require manual input.
As so many people access and edit this table there are issues with mis-clicking and typing which causes data to be overwritten without someone noticing they have done so.
Because of this issue I want to be able to lock specific columns in a row based on what the first cell in the row contains ("State" column).
In the instance that the state column contains the word "archived" I want to lock the entire row from having its contents being changed.
In the case of the word being "Ongoing" I want to lock column AA and AB in that row.
As it is sometimes is necessary to go back and edit information due to a known mistake I would need to have it so the State column always remains unlocked whatever it contains.
I have attached a redacted Excel sheet that contains my attempt at a coded solution.
https://drive.google.com/open?id=1rzTp0ur1tpXIY_Wa3cVlcwruJ7Q1rT
The code can also be seen below.
Note: I was not sure how to even go about fulfilling the requirement for the "Ongoing" condition so would really appreciate it if someone could point me in the right direction
Sub Locking()
Dim KeyCells As Range
Set KeyCells = Range("A3:A612")
For Each cell In Range("A3:A612")
If cell.Value = "Archived" Then
cell.EntireRow.Locked = True
ElseIf cell.Value = "Ongoing" Then
cell.EntireRow.Locked = False
ElseIf cell.Value = "Bad" Then
cell.EntireRow.Locked = False
End If
Next cell
End Sub
This is my first post on here as I could not find the solution from looking at several different stack overflow questions. I also watched numerous videos on VBA code, but am definitely missing something, and am struggling to figure out what it is.
If I have posted this incorrectly or extra detail would be helpful, please let me know.
Any and all help is extremely appreciated!
Thank you
Edit: Code works now
Instead of locking the entire row
cell.EntireRow.Locked = False
if you just want to lock AA and AB in that row do the following:
cell.EntireRow.Locked = False 'unlock entire row first
'then lock just the 2 rows
Range("AA" & cell.Row & ":AB" & cell.Row).Locked = True
The others would work the same way.
Currently I have two sheets in my spreadsheet.
On Sheet 1, I have 3 cells setup for how many tests passed, failed or received an NA (Actually labeling in Sheet 2 is- Pass, Fail and NA). On Sheet 2 (Cells V through AB), it contains PASS, Fail, and NA comments.
Sheet 1 picture:
Sheet 2 Picture:
I want to setup what is called I think a hyperlink but it does not function the way I need it too.
What I am trying to do:
For example, when clicking the cell B4 underneath UAT Passed in sheet 1, I want it to navigate to sheet 2 and either highlight or display only the cells that have the word Pass in them (with all the row details as well). I want to apply this to Fail and NA as well.
Along with this, in cells B4 through D4 on Sheet 1, I would want it show to the # of "Pass, Fail and NA" that exists through cells V through AB.
If I am not clear please let me know.
Here is my current setup/formula:
Use the Follow_Hyperlink event which has range called Target as a parameter, which is the cell containing the hyperlink. Use the range to set up your logic e.g:
If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
Sheets("Sheet2").Activate
End if
Figured out the answers on my own. The following formula worked best for me:
=CONCATENATE(COUNTIF(Script!V2:AB67,"PASS"))
=CONCATENATE(COUNTIF(Script!V2:AB67,"NA"))
=CONCATENATE(COUNTIF(Script!V2:AB67,"FAIL"))
I guess this needs a VB Macro. I need to know how to do this. I have an excel sheet,lets say with four columns - NAME, AGE, GENDER and BIRTHDAY. Suppose I want to ensure that the AGE column is always filled for all the records and is always positive and above zero. Number of records in the file are not fixed so file can have 5 rows or 500 rows. I need to make sure that if any of the columns NAME, GENDER or BIRTHDAY is filled in a row and AGE is blank, 0 or negative then excel should prevent the user from closing the file.
you can hack this solution a little to suit your needs
VBA Excel action when closing workbook
https://stackoverflow.com/a/27923799/6868389
Since the particular details of your question are so vague i can propose a solution to the closing part. The individual conditions you will have to add based on what exactly you have in the file and want but you can add them in between to set MyValidations to 1. As mentioned above this is based on Workbook_BeforeClose event.
https://msdn.microsoft.com/en-us/library/office/ff194765.aspx
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MyValidations = 1 Then
Cancel = False
Else
MsgBox "Nope'"
Cancel = True
End If
End Sub
I have created small excel form for updating a database. works great, though staff are doing odd things and have to replace the excel weekly with a clean version. So I am thinking of creating userforms that update the excel sheet(DutySelection).
I have many buttons (userform) A4:A31 that will control a single macro which opens 3 different userforms depending on B4:B31 dropdown list selection
Currently My code only works from B4 no matter which button i click.
EG: B4 selection Start, the Start form opens. B6 selection Finish, the Start form opens
Sub Duty()
If Sheets("DutySelection").Range("B4,B31") = "Start" Then
frmStart.Show
ElseIf Sheets("DutySelection").Range("B4,B31") = "Duty Type" Then
ReportUpdate.Show
Else: Sheets("DutySelection").Range("B4,B31") = "Finish" 'Then
frmFinish.Show
End If
End Sub
I am thinking that i am missing a line or two but just can not find what i am needing online
Sheet.Range("B4,B31") doesn't return what you think it does: it returns a composite range consisting of 2 areas, area 1 being cell B4 and area 2 being cell B31. I.e., the same as you would get when you select cell B4, then Ctrl-Clicked cell B31.
I think you meant "B4:B31", but this also returns something else: an array filled with (the values of) all cells in the range B4 to B31. You cannot compare it with a text string just like that.
What you do want here is to loop through all cells between B4 and B31, then compare their values to the texts you're interested in.
Another issue is that your code only ever acts upon the first text it matches. So, if cell B4 contains "Start", then there's no way the ElseIf will ever be evaluated, not even if cell B5 contains "Duty Type". The best way to deal with this depends on how you get those texts in column B on your sheet.
If I understood you correctly, you have a button in each row next to column B and clicking it invokes the action selected in column B in the corresponsing row, right?
In that case I would suggest that you place 3 buttons next to each other that invoke 3 different macros.
Greetings,
vat