+ Reply to Thread
Results 1 to 3 of 3

Change active cell into a specific location VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Wisbech England
    MS-Off Ver
    Excel 2010
    Posts
    308

    Change active cell into a specific location VBA

    Hi There
    I am having a problem with the below code and hoping that someone will help me here... it should update the sheet3 range A1:A5000 with the names of the photos in my photo folder and it does it but in an active sheet and active cell. how do I change this to a specific location like sheet3 range A1:A5000 so that it always update this range in this sheet even if it's not active????

    Thanks for any input :-)
    Here's a code:

    Private Sub CommandButton7_Click()
    
    
        Dim xRow As Long
        Dim xDirect$, xFname$, InitialFoldr$
    
        InitialFoldr$ = "G:\"    '<<< Startup folder to begin searching from
    
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & "\"
            .Title = "Please select a folder to list Files from"
            .InitialFileName = InitialFoldr$
            .Show
            If .SelectedItems.Count <> 0 Then
                xDirect$ = .SelectedItems(1) & "\"
                xFname$ = Dir(xDirect$, 7)
                Do While xFname$ <> ""
                    ActiveCell.Offset(xRow) = xFname$
                    xRow = xRow + 1
                    xFname$ = Dir
                Loop
             End If
        End With
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Change active cell into a specific location VBA

    Hi, ciapul12,

    maybe like this
    Private Sub CommandButton7_Click()
    
    
        Dim xDirect$, xFname$, InitialFoldr$
    
        InitialFoldr$ = "G:\"    '<<< Startup folder to begin searching from
    
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & "\"
            .Title = "Please select a folder to list Files from"
            .InitialFileName = InitialFoldr$
            .Show
            If .SelectedItems.Count <> 0 Then
                xDirect$ = .SelectedItems(1) & "\"
                xFname$ = Dir(xDirect$, 7)
                Do While xFname$ <> ""
                    Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = xFname$
                    xFname$ = Dir
                Loop
             End If
        End With
    End Sub
    This should add the names in Column A under the already filled range in Sheet3.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Wisbech England
    MS-Off Ver
    Excel 2010
    Posts
    308

    Re: Change active cell into a specific location VBA

    Thanks a lot buddy :-) This has worked perfectly!!

+ 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. Replies: 0
    Last Post: 07-11-2013, 02:08 AM
  2. [SOLVED] how to set the active cell to the macro button's location?
    By stingran in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-03-2013, 03:21 AM
  3. Replies: 1
    Last Post: 06-30-2013, 05:58 PM
  4. [SOLVED] Change active cell WHEN a specific cell value changes
    By scaffdog845 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-24-2012, 09:44 AM
  5. Return active cell's location/row
    By rziegler in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-09-2009, 05:29 PM

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