Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel VB Macro

  • 29-01-2007 2:08pm
    #1
    Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭


    I am creating a VB Macro which opens 10 files, merges the information by copying and pasting the info all into one file and then with the final big spreadsheet it creates a pivot table. However I cannot get it to copy the correct number of rows from each file because the "CTRL-A" function selects all the info but it is not the correct shape when pasting it into the "main" spreadsheet. How can I get it to only select the rows which has information in it and ignore other rows?

    Also when I am "appending" the main spreadsheet how do I get the cursor to automatically select the next empty row so the information is pasted at the bottom of the spreadsheet?


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    To select only the rows you want you need to look at using Ranges. Range(A1:J7).Select will, IIRC, select all the cells from A1 to J7. If not its not far off what will.

    For the empty row I can think of scrolling down selecting each row to see which is empty but there's probably a far smarter way than that.

    HTH.


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Yea think a loop system is best. Have realised this is one problem common to excel macros.

    Just when I am opening the files how do I get check if the files exist locally?

    Instead of full file paths "c:/some_folder/today/file_name.xls"

    How can I insert a relative file path?

    If I save the document countaining my macros in my "today" folder would this path do?

    "file_name.xls"

    cheers


  • Moderators, Politics Moderators Posts: 41,242 Mod ✭✭✭✭Seth Brundle


    use this to select all cells from A1 to J?:
    xlsApp.Range("A1", "J" & xlsApp.ActiveSheet.UsedRange.Rows.count).Select

    Use the CurDir() function to get the current path and then append the file name onto it.

    Use FSO to find out if the file exists.


Advertisement