how to select a column

dd*

New Member
Joined
May 20, 2011
Messages
10
2 questions:

I perform a search.
in the current active cell, I would like to select that column.
how do I select the whole column?


whats happening is its selecting the entire spreadsheets data

any ideas?

many thanks

dd
ps. you would think this was easy
 
Last edited:
This is my working code to select a column.
although i feel i need an if statement - if searchText found etc...

Code:
    Dim searchText As String
    Dim Found As Range
    
    searchText = "GL Code"
    
    Set Found = Cells.Find(What:=searchText, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
    
    If Not Found Is Nothing Then
        'Match Found
        If Found.Column > 1 Then
            Application.ScreenUpdating = False
            Range("A:A").Insert Shift:=xlToLeft 'insert column A
            Found.EntireColumn.Copy Destination:=Columns("A:A")
            Found.EntireColumn.Delete
            Application.ScreenUpdating = True
        End If
    Else
        MsgBox "No match found for '" & searchText & "'.", , "No Match Found"
    End If
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this:
Code:
Sub test()
    Dim intX                As Integer
    Dim strSearch           As String
    Dim rngFound            As Range
    Dim rngFoundCol         As Range
    
    strSearch = "GL Code"
    On Error Resume Next
    Set rngFound = Cells.Find(What:=strSearch, After:=Range("A1"), LookIn:=xlFormulas, _
                    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=False)
    On Error GoTo 0
    If rngFound Is Nothing Or rngFound.Column = 1 Then Exit Sub
    
    Application.ScreenUpdating = False
    Set rngFoundCol = rngFound.EntireColumn
    Range("A:A").Insert Shift:=xlToLeft
    Range("A:A").Value = rngFoundCol.Value
    rngFoundCol.Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I didnt see alphafrog's response there, but if you want to copy formatting, etc, use his method of copy/destination rather than what I did with value=value - that only copies the values. Not sure what your needs are.
 
Upvote 0
i think it was something like

Columns("A:A").Select


the result of the above code, is instead of selecting column A, it selects the whole spreadsheet.
i believe this is due to merged cells. this is how the users have created and worked with the spreadsheets, and copying & pasting data between spreadsheets.


many thanks again

dd
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,263
Members
449,307
Latest member
Andile

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