+ Reply to Thread
Results 1 to 6 of 6

Loop through certain cells column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Loop through certain cells column

    Hello people I hade made following code but I dont get it work,

    I want to loop through the whole column,
    then take the each cellvalue from column "L" *1.35
    put the new result same row but column K




    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

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Loop through certain cells column

    Does this help?

    Sub elmnasx()
    
    Dim ws As Worksheet
    Dim c As Range
    For Each ws In ThisWorkbook.Worksheets
    With ws
        For Each c In .Range("K2:K" & ws.UsedRange.Rows.Count)
             c.Value = c.Offset(, -1).Value * 1.35
        Next c
    End With
    Next ws
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: Loop through certain cells column

    I get this error
    run-time error '13':
    type mismatch

    RMpQMzc.png

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Loop through certain cells column

    Try:

    Sub elmnasx()
    
    Dim ws As Worksheet
    Dim c As Range
    For Each ws In ThisWorkbook.Worksheets
    With ws
        For Each c In .Range("K2:K" & .UsedRange.Rows.Count)
             c.Value = c.Offset(, -1).Value * 1.35
        Next c
    End With
    Next ws
    End Sub

  5. #5
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: Loop through certain cells column

    I solved it by myself

    Sub NoMatch()
    
    ActiveWS = ActiveSheet.UsedRange.Rows.Count 'count the number of rows used'
    Dim cell As Range
    
    For Each cell In Range("L1:L" & ActiveWS) 'define range of cells
        If InStr(1, cell.Value, "", vbTextCompare) > 0 Then ' if zero
        myresult = Val(cell.Value * 1.35) ' math formula
        Range("P" & cell.Row).Value = myresult 'result of math formula + cellvalue also do add in column P
        End If
    Next
    
    End Sub

  6. #6
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: Loop through certain cells column


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  2. [SOLVED] Loop through column and merge cells
    By christensen in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-10-2012, 04:17 AM
  3. loop through cells to last use column in a row
    By Beginner Level in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2012, 11:53 PM
  4. Loop to add together the Sum cells in a column
    By jaimie1664 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2011, 01:03 PM
  5. Loop thru cells in same column
    By jmicdk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2007, 02:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1