Trying to select a cell through VBA - skipping to several columns over

CWMacNut

New Member
Joined
Dec 28, 2018
Messages
11
Using the code below, I am trying to select the next cell down from the header so I can select just the data in the column without the header.

Code:
        For i = 1 To HeaderCount
                If HeaderNames(i) = "ZZZ" Then
'                        MsgBox ("Column # is: " & i)  ' [B][COLOR=#008000]<===== answers correctly[/COLOR][/B]
                        Cells(i & ",2").Select  ' [COLOR=#008000][B]<===== Selects cell (L1)!!!  i does not equal 12!![/B][/COLOR]
                        Range(Selection, Selection.End(xlDown)).Select
'                        Selection.Copy
                        Exit For
                End If
        Next

What on earth am I doing wrong??

Never mind! I am so sorry but I found the answer (Offset property). I will work on not being so quick to post -- do research BEFORE posting a question!!

Thank you,
CWMacNut
Graphics Engineer
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Cells wants row number and column number like this for example:

Cells(1,2)

which is row 1, column 2 or cell B1.
 
Upvote 0
Try
Code:
   For i = 1 To HeaderCount
      If HeaderNames(i) = "ZZZ" Then
         Range(Cells(2, i), Cells(Rows.Count, i).End(xlUp)).Copy
         Exit For
      End If
   Next i
 
Upvote 0
Think id go like this for your problem mind:

Code:
With Sheets("Sheet1")
    Set Rng = .Rows(1).Find(What:="XXX", LookIn:=xlValues, LookAt:=xlWhole)
    If Not Rng Is Nothing Then
        lr = .Cells(.Rows.Count, Rng.Column).End(xlUp).Row
        .Range(.Cells(2, Rng.Column), .Cells(lr, Rng.Column)).Copy
    Else
        MsgBox "Cant find the header"
    End If
End With
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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