+ Reply to Thread
Results 1 to 5 of 5

Count Rows With Offset

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Count Rows With Offset

    Hi!

    Does someone knows the code for counting rows with an offset?

    Before I was using the code bellow:

    lngLastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    I would like to use that same code but counting with an offset of 5 rows (every 5 rows I have the data to count)

    Any help would be much appreciated.

    Regards and happy 2013

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Count Rows With Offset

    Not exactly sur what your wanting. Can you upload a sample workbook?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Count Rows With Offset

    Hi,

    Attached an example workbook.

    Thanks!!!
    Attached Files Attached Files

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Count Rows With Offset

    This should get you going

    Option Explicit
    Sub Weather()
    Dim wsHoja1 As Worksheet
    Dim wsHoja2 As Worksheet
    Dim i As Long, ii As Long, destRow As Long
    Dim sDate As String
    
     Set wsHoja1 = Sheets("Weather")
     Set wsHoja2 = Sheets("Data")
     
     destRow = 9
    For i = 11 To wsHoja1.Cells(Rows.Count, "b").End(xlUp).Row Step 5
        sDate = wsHoja1.Cells(i, "B").Value
        For ii = 1 To 4
            If Not wsHoja1.Cells(i, "B").Offset(ii) = vbNullString Then
                wsHoja2.Cells(destRow, "B").Value = sDate
                wsHoja2.Cells(destRow, "C").Value = wsHoja1.Cells(i, "B").Offset(ii)
                wsHoja2.Cells(destRow, "E").Value = wsHoja1.Cells(i, "D").Offset(ii)
                wsHoja2.Cells(destRow, "F").Value = wsHoja1.Cells(i, "E").Offset(ii)
                destRow = destRow + 1
            End If
        Next
    Next
     Set wsHoja1 = Nothing
     Set wsHoja2 = Nothing
    End Sub

  5. #5
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Count Rows With Offset

    Excellent Mike!!

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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