mkvarious
New Member
- Joined
- Jan 24, 2013
- Messages
- 44
hello,
I need a help with the following task: when a cell from H column is changed then I need a formula in I cell column to be written. Obviously I do not want to use Excel formulas like: =if(H1="","",weeknum(H1)) or any other variation of any formula as the file needs to be used by various users and as usual in such instances they will/can delete the formula etc. etc.
So I need VBA code that reacts to workbook events. I have tried many variations and still did not get what I am looking for. not sure, but think that my problem is that I narrow the SELECTION CHANGE to column H only and then it does not always work. I am even using SHEET CHANGE to get the expected result but am not getting it at right.
below (one) of the variation codes I have been trying. since I have limited SELECTION CHANGE and SHEET CHANGE to check whether H column is empty or not, then I realized that:
what I need is: when data has been inputted in H cell, then a formula needs to be written in I cell (forget the formula now, I need the event to work, first). I need this/these events to work when cells in H columns have been changed by:
since I am clueless how to get that working can someone help me, please?
do I need two events or just one, but properly written?
cheers,
mkvarious
msgbox is obviously used for tracking purposes, only
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim który As Long
If Target.Column = 8 Then
If ActiveCell.Value <> "" Then
który = ActiveCell.Row
MsgBox "selection change"
MsgBox który
ActiveCell.Offset(0, 1).Formula = "=weeknum(" & Cells(ActiveCell.Row, "H") & ",2)"
End If
End If
End sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim który As Long
If Target.Column = 8 Then
If ActiveCell.Value <> "" Then
który = ActiveCell.Row
MsgBox "sheet change"
MsgBox który
ActiveCell.Offset(0, 1).Formula = "=weeknum(" & Cells(ActiveCell.Row, "H") & ",2)"
End If
End Sub
I need a help with the following task: when a cell from H column is changed then I need a formula in I cell column to be written. Obviously I do not want to use Excel formulas like: =if(H1="","",weeknum(H1)) or any other variation of any formula as the file needs to be used by various users and as usual in such instances they will/can delete the formula etc. etc.
So I need VBA code that reacts to workbook events. I have tried many variations and still did not get what I am looking for. not sure, but think that my problem is that I narrow the SELECTION CHANGE to column H only and then it does not always work. I am even using SHEET CHANGE to get the expected result but am not getting it at right.
below (one) of the variation codes I have been trying. since I have limited SELECTION CHANGE and SHEET CHANGE to check whether H column is empty or not, then I realized that:
- when I input data in H column to na empty cell and press enter they (SELECTION CHANGE/SHEET CHANGE) do nothing
- when I input data in H column to na empty cell and press tab they do nothing
- when I input data in H column to na empty cell and press ctrl + enter one of them works (SHEET CHANGE works) and writes the formula in I cell
- when I use cursors to get to a cell with data in H column then it works (SELECTION CHANGE works) and writes the formula in I cell
what I need is: when data has been inputted in H cell, then a formula needs to be written in I cell (forget the formula now, I need the event to work, first). I need this/these events to work when cells in H columns have been changed by:
- pressing enter
- pressing tab
- using cursors
- pressing ctrl + tab
since I am clueless how to get that working can someone help me, please?
do I need two events or just one, but properly written?
cheers,
mkvarious
msgbox is obviously used for tracking purposes, only
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim który As Long
If Target.Column = 8 Then
If ActiveCell.Value <> "" Then
który = ActiveCell.Row
MsgBox "selection change"
MsgBox który
ActiveCell.Offset(0, 1).Formula = "=weeknum(" & Cells(ActiveCell.Row, "H") & ",2)"
End If
End If
End sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim który As Long
If Target.Column = 8 Then
If ActiveCell.Value <> "" Then
który = ActiveCell.Row
MsgBox "sheet change"
MsgBox który
ActiveCell.Offset(0, 1).Formula = "=weeknum(" & Cells(ActiveCell.Row, "H") & ",2)"
End If
End Sub