Forum Discussion
convert excel formula to vba code
- Oct 28, 2022
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("I:I"), Target) Is Nothing Then If Target.Count > 1 Then Exit Sub End If ' clean the value Debug.Print Target.Address If Trim(Target.Value) <> "" Then If Range("I" & Target.Row).Value < 1 Then Range("M" & Target.Row).Value = Range("K" & Target.Row).Value Else Range("M" & Target.Row).Value = ((Range("K" & Target.Row).Value) + (Range("I" & Target.Row).Value) - 1) End If Else Range("M" & Target.Row).Value = "" End If End If End SubThis code works in my sheet.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("I:I"), Target) Is Nothing Then
If Target.Count > 1 Then
Exit Sub
End If
' clean the value
Debug.Print Target.Address
If Trim(Target.Value) <> "" Then
If Range("I" & Target.Row).Value < 1 Then
Range("M" & Target.Row).Value = Range("K" & Target.Row).Value
Else
Range("M" & Target.Row).Value = ((Range("K" & Target.Row).Value) + (Range("I" & Target.Row).Value) - 1)
End If
Else
Range("M" & Target.Row).Value = ""
End If
End If
End SubThis code works in my sheet.
Thank you very much!
- kimmie2430Nov 02, 2022Copper Contributor
Hi OliverScheurich ,
I have tried to follow your step to clear all the formula on column O, but the error msg still popping out...
Then i look for the circular reference on formula tab but there is no more...
Could you please check for me please?
Im uploading the excel file for your perusal...
THank you very much...
- kimmie2430Nov 02, 2022Copper ContributorOliverScheurich
alright, sure, thanks for your help! - OliverScheurichNov 01, 2022Gold Contributor
You are welcome. I'm not sure what you want to do with columns P & Q. Maybe you want to start a new discussion and ask the experts of the Community.
- kimmie2430Nov 01, 2022Copper ContributorHi OliverScheurich,
Thanks for helping on the error... It is helpful...
Could you please help on the 2 previous formulas on the column P & Q as well?
Thank you very much.. - OliverScheurichOct 31, 2022Gold Contributor
There are cells with circular references in sheet "CompletedTask". For example in cell O84 there is a formula which contains the cell O84.
=IF(R84="Completed", IF(O84="",NOW(), O84), "")This means the error message is not related to columns P & Q. You only have to correct the formulas in column O which have circular references.
- kimmie2430Oct 31, 2022Copper Contributor
Can u please help me to convert the column P & Q to vba as well? Because the error pop up msg as below is annoying....it come out whenever i open this excel...
Im not sure if the formula is correct, but i would like to have The formula on column P is, IF column R = Completed or Make appointment, column P = column O - column N +1, else, column P is empty.
which means when column N= 30 oct, column O = 31 Oct, actual duration of day on column P =2 days (include the first day).For column Q,
IF column R = Completed or Make appointment, column Q = column O - column K /7 and round up, else, column P is empty.
which means when column K= 30 oct, column O = 31 Oct, actual duration of weeks on column Q =1 week (include the first day); when column K= 20 oct, column O = 27 Oct, actual duration of weeks on column Q =1 week; when column K= 20 oct, column O = 28 Oct, actual duration of weeks on column Q =2 weeks.For the above 2 formulas, No matter how the column R is change after once Completed or Make appointment is selected, column O P Q will remain unchange.
Attached below with the file for your perusal.
Thank you very much!!