Find last used column,then find every 3rd cell in that column

jon321

New Member
Joined
Oct 27, 2008
Messages
47
I need to find the last used column in my spreadsheet which i already have a working code for:

Sub Button2_Click()
Dim LastRow As Long, LastColumn As Integer

LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
LastColumn = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column

Columns(LastColumn).Select
End Sub


Then I need to find every 3rd cell in that column, i also have a code for this but i dont know how to make these work as one code as at the minute this is in a set column!

Sub Button1_Click()
Dim rRange As Range
Dim rEveryNth As Range
Dim lRow As Long

With Sheet1
Set rRange = .Range("c1", .Cells(.Rows.Count, "C").End(xlUp))
End With

For lRow = 1 To rRange.Rows.Count Step 3
If lRow = 1 Then
Set rEveryNth = rRange(lRow, 1)
Else
Set rEveryNth = Union(rRange(lRow, 1), rEveryNth)
End If
Next lRow

Application.Goto rEveryNth
End Sub


Please help
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
jon321,

Try, for just Button1_Click:

Code:
Sub Button1_Click()
    Dim rRange As Range
    Dim rEveryNth As Range
    Dim lRow, lCol As Long
    
    With Sheet1
        lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        lRow = Cells(Rows.Count, lCol).End(xlUp).Row
        Set rRange = .Range(Cells(1, lCol), Cells(lRow, lCol))
    End With

    For lRow = 1 To rRange.Rows.Count Step 3
        If lRow = 1 Then
            Set rEveryNth = rRange(lRow, 1)
        Else
            Set rEveryNth = Union(rRange(lRow, 1), rEveryNth)
        End If
    Next lRow
    
    Application.Goto rEveryNth
End Sub


Have a great day,
Stan
 
Upvote 0
Hi, This might help
Code:
Dim lastcolumn, Col As String, rRange As Range
 lastcolumn = ActiveSheet.UsedRange.Address
   Col = Split(Split(lastcolumn, ":")(1), "$")(1)
      Set rRange = Range(Range(Col & "1"), Range(Col & Rows.Count).End(xlUp))
       MsgBox rRange.Address
Regards Mick
 
Upvote 0
Stan that version works great, however i do have a few blank cells dotted around within my formatting, the first code i posted seemed to bypass this and go straight to the exact column i needed whereas yours doesnt if theres a blank cell before that column.. any suggestions??

Many thanks
 
Upvote 0
jon321,

Try, for just Button1_Click:

Code:
Option Explicit
Sub Button1_Click()
    Dim rRange As Range
    Dim rEveryNth As Range
    Dim lRow, lCol As Long
    With Sheet1
        lCol = .UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
        lRow = Cells(Rows.Count, lCol).End(xlUp).Row
        Set rRange = .Range(Cells(1, lCol), Cells(lRow, lCol))
    End With
    For lRow = 1 To rRange.Rows.Count Step 3
        If lRow = 1 Then
            Set rEveryNth = rRange(lRow, 1)
        Else
            Set rEveryNth = Union(rRange(lRow, 1), rEveryNth)
        End If
    Next lRow
    Application.Goto rEveryNth
End Sub


Have a great day,
Stan
 
Last edited:
Upvote 0
that works great!!, final thing though i need it to start a set number of rows from the top.. say 5 or something can i change your code to achieve this?

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,860
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top