Apply formula to entire column with a macro in VBA

croger152003

New Member
Joined
Apr 26, 2018
Messages
2
I download data from our Jets and one of the fields I see is the fuel pressure, the fuel pressure sensor has a signal voltage between 1-5 v. With the flight data depending on how long the flight was it could be any where between a few thousand data points to several 100k data points. The formula I need to apply is V * 205 / 2.5 + -78, V= the data in each cell of BF2 and on, this macro is needed because I can talk someone through using a macro easier than a whole process of applying a formula to all 350k cells. Ideally the formula would be something that has a start of BF2 and ends where there is no data automatically.

I know excel enough to get into trouble sometimes but not always enough to make things work the way I want, and and all help is appreciated.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi croger152003,

Welcome to the MrExcel forum.

The only issue I see is that the column BF can either contain data points or a formula but not both, you would need to put the formula into another column. In this code I used column BG for the formula to fill down.

Code:
Sub Volts()


    Dim lrow As Long
    
    lrow = Cells(Rows.Count, "BF").End(xlUp).Row
    Range("BG2").Formula = "=BF2*205/2.5+-78"
    Range("BG2").AutoFill Destination:=Range("BG2:BG" & lrow)
    
End Sub

I hope this helps.
 
Upvote 0
This script would put the results of the formula into the cell not the formula. Would this work?

Code:
Sub Test()
'Modified 4/26/2018 8:15 PM  EDT
Application.ScreenUpdating = False
Dim c As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "BF").End(xlUp).Row
    For Each c In Range("BF2:BF" & Lastrow)
         c.Value = c.Value * 205 / 2.5 + -78
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This script would put the results of the formula into the cell not the formula. Would this work?

Code:
Sub Test()
'Modified 4/26/2018 8:15 PM  EDT
Application.ScreenUpdating = False
Dim c As Range
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "BF").End(xlUp).Row
    For Each c In Range("BF2:BF" & Lastrow)
         c.Value = c.Value * 205 / 2.5 + -78
    Next
Application.ScreenUpdating = True
End Sub

This is exactly what I was looking for, this worked perfectly and gives the pressure number exactly.

Thank you so much
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
This is exactly what I was looking for, this worked perfectly and gives the pressure number exactly.

Thank you so much
 
Upvote 0
Hi croger152003,

Welcome to the MrExcel forum.

The only issue I see is that the column BF can either contain data points or a formula but not both, you would need to put the formula into another column. In this code I used column BG for the formula to fill down.

Code:
Sub Volts()


    Dim lrow As Long
   
    lrow = Cells(Rows.Count, "BF").End(xlUp).Row
    Range("BG2").Formula = "=BF2*205/2.5+-78"
    Range("BG2").AutoFill Destination:=Range("BG2:BG" & lrow)
   
End Sub

I hope this helps.
Dim lrow As Long

lrow = Cells(Rows.Count, "L").End(xlUp).Row
Range("L6").Formula = "=CONCATENATE(RC[-4],""-AGIS"")"
Range("L6").AutoFill Destination:=Range("L6:L" & lrow)
End Sub

Use this code but giving error as
AutoFill method of range class failed
 
Upvote 0
Your code as written (direct copy & paste) worked for me with no errors.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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