PDA

View Full Version : [SOLVED:] Need help with a loop



elmnas
06-22-2015, 05:37 AM
Hello People,

How do I loop through a whole column from row 2 to last used cell in column L?


I got this code so far



Dim ws As Worksheet


For Each ws In ThisWorkbook.Worksheets
Dim c As Range


For Each c In ws.UsedRange.Columns("L").Cells


Dim mycell As String
Dim nomatchfom As String

mycell = c.Value
nomatchform = 1.35


myresult = Val(mycell * nomatchform)

MsgBox myresult

Next c
Next ws








Thank you in advance.

snb
06-22-2015, 06:15 AM
Sub M_snb()
For Each sh In Sheets
sh.UsedRange.Columns(12).Name = "elmnas"
[elmnas] = [elmnas*1.35]
Next
End Sub

elmnas
06-22-2015, 06:35 AM
I think you totally missunderstood the question...

snb
06-22-2015, 06:43 AM
I think you didn't even test the answer.

SamT
06-22-2015, 07:07 AM
Dim ws As Worksheet
Dim c As Range
Dim mycell As Variant
Const nomatchform As Double = 1.35

For Each ws In ThisWorkbook.Worksheets
For Each c In ws.UsedRange.Columns("L").Cells
mycell = Val(c.Value )
myresult = mycell * nomatchform
MsgBox myresult
Next c
Next ws

That is just your code written in proper form. snb's is faster.

From your code, it appears that Column L has numbers, numbers as strings, is formatted as Text, has numbers and text in the same cell, or a mix of any or all the above. "Val" pulls leading numbers from strings, even mixed strings.

Val(" 1615 198th Street N.E.") = 1615198

Val("Test 50") = 0

Val("11. 20 Test") = 11.2

It may be handy
Val("11 e 20 Test") = 1.1E+21

apo
06-22-2015, 08:28 AM
http://www.excelforum.com/excel-programming-vba-macros/1089588-loop-through-certain-cells-column.html

SamT
06-22-2015, 11:35 AM
Solved at cross post.