Hello,
I am very new to VBA.
Could somebody please decipher the following VBA code:
Capture.jpg
What exactly does MyConvert do? Thank you!
Hello,
I am very new to VBA.
Could somebody please decipher the following VBA code:
Capture.jpg
What exactly does MyConvert do? Thank you!
.
Overall this macro is a quick means of multiplying any number in a cell by 5% and obtaining the answer in the same cell. (Replaces whatever number was there initially).
The macro was missing a few lines of code. Here is the updated version :
Paste the macro into a Routine Module, paste a command button on Sheet1, and enter any number you want into any cell on Sheet1. Click on that cell so it is selected, then click on the button.Sub MyConvert() Dim SelRange As Range Dim c As Range Set SelRange = Selection For Each c In SelRange c.Select If IsNumeric(c) Then If Left(ActiveCell.Formula, 1) <> "=" Then ActiveCell.Formula = "=" + ActiveCell.Formula + "*5%" End If End If Next End Sub
Explanation :
Sub MyConvert() Dim SelRange As Range 'establishes SelRange variable as a range Set SelRange = Selection 'In other words, any cell selected will be the SelRange For Each c In SelRange 'For all the cells you select (could be more than one cell) c.Select 'Selected cell / s If IsNumeric(c) Then 'If the content is a number If Left(ActiveCell.Formula, 1) <> "=" Then 'If there isn't a formula in the cell already then ... Active.Cell.Formula = "=" + ActiveCell.Formula + "*5%" 'create a formula that multiplies the existing number by 5% End If End If Next End Sub
suffices.Sub M_snb() for each it in selection.specialcells(-4123) next End Sub