Totally green here. I am trying to write a macro that first cleans up some unnecessary data and spacing in a Sheet, then completes this task:
Within A:A, If cell text contains "specific text", insert given formula in column B/D/F on the same row as the cell containing "specific text".
I am trying to automate the conversion of values from one unit to another. The type of unit is associated with the value of something in a Cell of A:A, and the formula needs to act on a value in B:B (area), D:D (length), or F:F (count) based on what unit the Cell of A:A is in.
The Column locations of the data will always be the same, but the order of the Rows changes from document to document.
How do I get the conversion formulas to apply to the desired cell value? How can I get the macro to run even if text is added to the Cell in A:A?
I've used the Macro Recorder to write the formatting, and to prepare the formulas I will use in the Result strings.
Cleanup Step
Sub Takeoff()
'
' Takeoff Macro
'
'
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Columns("H:O").Select
Selection.ClearContents
Columns("B:G").Select
Selection.EntireColumn.AutoFit
Columns("A:I").Select
Selection.NumberFormat = "#,##0.00"
End Sub
Conversion Step
I think I would use something like the following, repeating the If/Then for each conversion case. The cell in A:A will always contain something to act on, but there may be additional text after that text - is If/Then the best way to do this?
Dim Entry As String, result As String
Entry = Range("A:A").Value
If Entry = "Slope Mat" Then
Range("H:H").Value = result
Formulas for Conversion
I think the RC[-x] will keep the result in the same row, as desired.
"=RC[-4]*2"
"=RC[-6]*0.00184"
"=ROUNDUP(1.14*CONVERT(RC[-6],""ft^2"",""yd^2""),-2)"
"=CONVERT(RC[-6],""ft^2"",""us_acre"")"
When run, this macro should
- Clean up the spreadsheet
- Search for strings and, when found, paste a formula in the desired row
Thank you very much for your patience and help.
Aucun commentaire:
Enregistrer un commentaire