I have a spreadsheet as follows:
Columns A:G (Name, Path, Size, Type, DateCreated, DateLastModified, DateLast Accessed)
Header uses rows 1:7
- ColumnC contains file size in KB
- Primary VBA populates from selected folder
- Sub inserts 2 columns to left of ColumnD
- Columns now: Name, Path, Size in KB, Size in MB, Size in GB, Type, DateCreated, DateLastModified, DateLast Accessed
I have a Sub to call which loops ColumnC to and inserts a divided amount into ColumnD & ColumnE
Looping works but takes time so would like to PasteSpecial where ColumnD = ColumnC/1000000 and ColumnE = ColumnC/1000000000
Each folder will have different quantities of files. To run the conversion Call I am using myRows = Cells(Rows.Count, 3).End(xlUp).Row - 7
(where 7 is the header-row deduction)"
I would like to PasteSpecial the myRows of ColumnC to ColumnD and ColumnE but, as noted myRows will be different for each folder. I am not finding (but still searching) where to put the divisor which will be used for the ColumnD and ColumnE calculation with:
PasteSpecial Operation:=xlPastSpecialOperationDivide
My Call code is:
Sub Convert_MB_GB()
Dim myRows As Long
Dim x As Long
Dim var As Double
Dim Num1 As Long
Dim Num2 As Long
Num1 = 1000000 'Divisor for KB to MB
Num2 = 1000000000 'Divisor for KB to GB
myRows = Cells(Rows.Count, 3).End(xlUp).Row - 7 'Count rows and subtract 7-row header
Range("D:E").Insert 'Insert 2 columns to the left of Column D
[D7].Value = "Size in MB" 'Add title to column
[E7].Value = "Size in GB" 'Add title to column
Range("C8").Select 'Starting Cell
For x = 1 To myRows
var = Application.ActiveCell.Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = var / Num1
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = var / Num2
ActiveCell.Offset(1, 0).Select
ActiveCell.Offset(0, -2).Select
Next
Range("D:D").NumberFormat = "0.0" 'Configure Column D to 1 decimal point
Range("E:E").NumberFormat = "0.0" 'Configure Column E to 1 decimal point
End Sub