Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50076

[SOLVED] Update Same Column

$
0
0
Dear All,
I have the following code and I would like the code to print the outcome in the same column as the range, so ideally the code would be updating the column F, if possible.

Code:

Sub update_2()
Dim Rng    As Range
Dim Dn      As Range
Dim n      As Integer
Dim Num    As String
Set Rng = Range(Range("F1"), Range("F" & Rows.Count).End(xlUp))
{add code for updating column F}

For Each Dn In Rng
    If Not Dn.Offset(, 2) = "BP" Then
        For n = 1 To Len(Dn)
            If IsNumeric(Mid(Dn, n, 1)) Or Mid(Dn, n, 1) = Chr(46) Then
                Num = Num & Mid(Dn, n, 1)
            End If
        Next n
   
    If IsNumeric(Left(Dn, 1)) Or Len(Num) = Len(Dn) Then
    Dn.Offset(, 1) = Num
   
    ElseIf InStr(Dn, "-") Then
      Dn.Offset(, 1) = Split(Dn, "-") ' And Mid(Dn, n, 1)

    'The select case statements calculate input string values from coloumn E, if they start with L20s, Vl30s, H20s, M70s.
    ElseIf Num = "" Then
        Select Case Dn
            Case "VLteens": Dn.Offset(, 1) = 13
            Case "Mhteens": Dn.Offset(, 1) = 17
        End Select

Input --> Example: Column F
40.50
P20s
89.90
L20s

(after the code is run)
Output--> Example: Column F
40.50
22
89.90
22

Any help would be very much appreciated.
Thank you for your time and response.

Viewing all articles
Browse latest Browse all 50076

Trending Articles