Help converting formula to VBA

Frank3923

Board Regular
Joined
Jan 20, 2003
Messages
244
I need assistance in converting a formula over to vba, I have inserted the formula, as well as my attempt to change it. Being that I am not a programmer, I would appreciate any assistance in showing me, the proper way to list the formula into the mace

formula needed to be inserted

=LEFT(G8,FIND("(",G8)-1)

This is my attempt to create it, in VBA

Range("E" & i + 1).Formula = "=Left(Range(G" & i + 1 & Find(" ""("", Range("G" & i)-1 & ")"
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Thank you for the quick response.

I inserted the formula, and it, is returning a "False" value.
It is returning the False response in the cell, that I want the value in.

Do you have any further suggestions?

Thank you
 
Upvote 0
How about this?

Range("E" & i).Formula = "=LEFT(G" & i & ",FIND(""("",G" & i & ")-1)"

Note I removed the +1 from you i+1 because I'm not sure why it is there (just run your loop one lower I would think).
 
Upvote 0
Thank you for the response.

I added your line in, and when I go to run it, I am getting a compile error.

"Next without for",

I have enclosed the code below. you can see that the 3rd line is:

For i = 1 To LR

So I am a little confused, as to why I am getting the error message


Sub Get_TValue()
Dim LR As Long: LR = Range("G" & Rows.Count).End(xlUp).Row


For i = 1 To LR
If Trim(Range("G" & i).Value) = "Final" Then
Range("E" & i + 1).Formula = Range("E" & i).Formula = "=LEFT(G" & i & ",FIND(""("",G" & i & ")-1)"
Next i

End Sub
 
Upvote 0
I added your line in, and when I go to run it, I am getting a compile error.

"Next without for",

Sub Get_TValue()
Dim LR As Long: LR = Range("G" & Rows.Count).End(xlUp).Row


For i = 1 To LR
If Trim(Range("G" & i).Value) = "Final" Then
Range("E" & i + 1).Formula = Range("E" & i).Formula = "=LEFT(G" & i & ",FIND(""("",G" & i & ")-1)"
Next i

End Sub
Either you need to put the assignment statement on the same line as the If..Then statement like this...

Code:
Sub Get_TValue()
  Dim LR As Long: LR = Range("G" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
    If Trim(Range("G" & i).Value) = "Final" Then Range("E" & i + 1).Formula = Range("E" & i).Formula = "=LEFT(G" & i & ",FIND(""("",G" & i & ")-1)"
  Next i
End Sub
or you need to add an End If statement like this...

Code:
Sub Get_TValue()
  Dim LR As Long: LR = Range("G" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
    If Trim(Range("G" & i).Value) = "Final" Then
      Range("E" & i + 1).Formula = Range("E" & i).Formula = "=LEFT(G" & i & ",FIND(""("",G" & i & ")-1)"
    End If
  Next i
End Sub
depending on if you want a single line If..Then statement or an If..Then statement block.
 
Upvote 0
The End If, cured the error message.

But, I still received the same results "False", and there is no formula showing in the cell.

any ideas?

Thank you in advance.
 
Upvote 0
Yes, Jen. There is a ( in the cell.

I did manually type in this formula, into a cell, and it returns the correct results.

In both yours and Ricks methods, it returns the same results, "FALSE", and there is no reflection of a formula, being in that cell.

this is the formula, that I manually entered.
=LEFT(G6,FIND("(",G6)-1)

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top