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
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