Is there any way to get a specific value "66" in "B1" when I Put Text "Ok" in "A1" without entering Formula in "B1"
You can try Worksheet_Change event. Try below codes.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B1")) Is Nothing Then
If Val(Target.Value) = 66 Then
Range("A1") = "Ok"
End If
End If
End Sub
Related
I have a cell which i declared as active cell using developers tool in excel
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("C1").Value = ActiveCell.Value
End Sub
this cell is equals to the value of a drop down cell i created from data validation.
My Problem is cell C1 is not changing when i select a new value from the drop down
Here you go. When B1 is changed C1 is assigned the value of B1. It doesn't matter how the change was carried out, from the keyboard or by selection from a drop-down.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B1").Address Then
' prevent the coming change from causing a call of this procedure
Application.EnableEvents = False
Cells(1, "C").Value = Target.Value
Application.EnableEvents = True
End If
End Sub
I have a Dynamic Table that changes based on the value of B1.
I want the value of B1 to change by clicking on another cell from another workbook. I'm super new to VBA and don't really know what I'm doing.
What I want is to click on any cell from column E and it will change the value of B1 to equal value of column O.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("E2:E")) Is Nothing Then
Worksheets("Dynamic Table").Range("B1").Value = ActiveCell.Offest(0, 10)
End If
End If
End Sub
My Amateur Code
Do you mean sth like that
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 5 Then
If Target.Cells.CountLarge = 1 Then
Worksheets("Dynamic Table").Range("B1").Value = Target.Offset(, 10).Value
End If
End If
End Sub
I assumed you mean with another workbook just another worksheet.
I am using following macro to show value of clicked cell (range A5:A200) in A1 cell:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("A5:A200")) Is Nothing Then
Range("A1").Value = Selection.Value
End If
End If
End Sub
...and it works great. Additionally in A2 I'd like to show related value from C column.
Example:
I click on A10 -> and see the value in A1, then in A2 i'd like to see the value from C10 cell
You can utilize the .row property of Selection. But, you already have Target being used from the arugument within the Worksheet_Selection() event as your "Selection" range, and using that range is preferred over using selection.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Range("A5:A200")) Is Nothing Then
Range("A1").Value = Target.Value
Range("A2").Value = Cells(Target.row, "C")
End If
End If
End Sub
So replace your selection ranges with Target, and use the row property within Cell() to get your value from the C column.
I am trying to autofill text in a range(N6:N125) in excel 2013 via vba. My code works fine when range refers a single cell but not for a range. could you help me to find my mistake? My code is
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("N6:N125") = "" Then
Range("N6:N125").value = "My Text"
End If
End Sub
If you want to fill only the empty cells in N6 through N125 and some of the cells may already have values, but none have formulas, then a loop is not actually needed:
Sub marine()
Dim r As Range, s As String
Set r = Range("N6:N125")
s = "=IF(N6:N125="""",""MyText"",N6:N125)"
r.Value = Evaluate(s)
End Sub
If Range("N6:N125") = "" Then
This doesn't do the job. You will need to do this test cell-by-cell. An easier alternative would be this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Range("N6:N125").SpecialCells(xlCellTypeBlanks).value = "My Text"
End Sub
This will fill empty cells within the range. BUT, if the intent of your test is to check whether the whole range is empty, this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CountA(Range("N6:N125")) = 0 Then Range("N6:N125").value = "My Text"
End Sub
You can use:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Selection
For Each cell In Selection
If cell = "" Then
cell.Value = "My Text"
End If
Next cell
End With
End Sub
This code will test each cell in your selection if empty and write "My Text" in it, but if it is not empty it will skip it.
In your code you are not testing each cell and you are not using a loop to move from one cell to another
My problem is the following:
The function below triggers an "if then function" when i manually change the value in cell D9. What should I do to get it to work with an automatic value change of cell D9 trough a link.
In other words if i where to link cell D9 to cell A1 and change the value of A1 can i still make the function below work?
Private Sub Worksheet_Change(ByVal Target As range)
If Target.Address = "$D$9" Then
If range("C12") = 0 Then
Rows("12:12").Select
Selection.RowHeight = 0
Else:
Rows("12:12").Select
Selection.RowHeight = 15
End If
End Sub
How about something like this:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim rngDependents As Range
Set rngDependents = Target.Dependents
If Target.Address = "$D$9" Then
MsgBox "D9 has changed"
ElseIf Not Intersect(rngDependents, Range("$D$9")) Is Nothing Then
MsgBox "D9 has been changed indirectly"
End If
End Sub
try to make your function then in other cell use the function with input the link to the cell d9.
When you change the value at cell d9 your function will be evaluated.