Formula function not working

vba317

Board Regular
Joined
Oct 7, 2015
Messages
58
What I am trying to do is use vba to loop through all the worksheets in my workbook and multiply a range of values by 100 in three columns: AA,AB and AC. After doing research I found a function that works for the first two columns AA and AB the numbers in columns AA and AB are correct the value in the cell *100, but for some reason all values in column AC are entered in as formula =AD(row number) *100 since all values in columns AD =1 the result is 100 in all cells.
Any help is appreciated
Tom

Code:
Public Sub MultiplyColumns()
Dim wrkBk As Excel.Workbook
Dim wrkSh As Excel.Worksheet
Dim lngLastRow As Long
Dim lngSheet As Long
Dim lngWrkShCnt As Long
Dim varRange As Variant
Dim rngSheet As Range
Dim rngCol As Range
Dim lngRow As Long
Dim lngCol As Long
Dim lngCellValue As Long
Dim strColName As String


Set wrkBk = ActiveWorkbook
Set wrkSh = wrkBk.Sheets(4)
lngLastRow = wrkSh.Range("AA" & Rows.Count).End(xlUp).Row
lngWrkShCnt = Worksheets.Count
Set rngCol = Range("A3:AJ" & Rows.Count)


'Loops through all worksheets starting at Worksheet 4 Age of Vehicle Current MC Fctr
For lngSheet = 4 To lngWrkShCnt
'Convert all Columns to Number
lngCol = 1
lngRow = 3
For Each rngCol In ActiveSheet.UsedRange.Columns
        'Converts all values to numbers
         If WorksheetFunction.CountA(rngCol) <> 0 Then
               Columns(rngCol.Column).TextToColumns _
               Destination:=Cells(1, rngCol.Column), _
               DataType:=xlDelimited, _
               TextQualifier:=xlDoubleQuote, _
               ConsecutiveDelimiter:=False, _
               Tab:=True, _
               Semicolon:=False, _
               Comma:=False, _
               Space:=False, _
               Other:=False, _
               FieldInfo:=Array(1, 1), _
               TrailingMinusNumbers:=True
           End If
            'Multiply all values times 100
            Debug.Print "Column Number ", lngCol
              strColName = ColNumToLetter(lngCol)
                If strColName = "AA" Then
                    If wrkSh.Range("AA3") = "No Information" Or wrkSh.Range("AA3") = "No Data" Then
                        wrkSh.Range("AA3").Delete Shift:=xlUp
                    End If
                    If wrkSh.Range("AB3") = "No Information" Or wrkSh.Range("AA3") = "No Data" Then
                        wrkSh.Range("AB3").Delete Shift:=xlUp
                    End If
                    If wrkSh.Range("AC3") = "No Information" Or wrkSh.Range("AA3") = "No Data" Then
                        wrkSh.Range("AC3").Delete Shift:=xlUp
                    End If
                End If
                If lngCol = 27 Then Stop
                If lngCol > 26 And lngCol < 30 Then
                    With Range(strColName & "3", strColName & lngLastRow)
                        .Formula = "=rc[1]*100"
                        .Value = .Value
                    End With
                End If
'           lngCol = lngCol + 1
            lngRow = lngRow + 1
    Next rngCol
Set wrkSh = wrkBk.Sheets(lngSheet)
Next lngSheet
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I have decided to approach things a different way, I have changed the code and now the code works.

Code:
 If lngCol > 26 And lngCol < 30 Then
                Set rngData = wrkSh.Range(strColName & "3", strColName & lngLastRow)
                     rngData = Evaluate(rngData.Address & "*100")
 End If
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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