Consulting

Results 1 to 8 of 8

Thread: Pasting into an existing column

  1. #1
    VBAX Regular
    Joined
    Jul 2016
    Posts
    35
    Location

    Pasting into an existing column

    Ok, I'm new to vba as of right now but learning to help people more efficient in my office. Currently we use quickbooks and when exporting financials to excel it returns something like this:

    Income
    Maintenance
    Landscaping
    Total Commerical
    Landscaping
    Landscaping
    Customer Discount
    Landscaping - Other
    Residential
    Total Landscaping

    So I've created a vba code that literally hardcodes cut and pastes every single one of these cells and puts them into column a
    For instance:
    Sheets("New").Select
    Range("B5:B21").Cut Range("A5:A21")
    I done this for every single cell. This works for this specific worksheet but if I export another worksheet that has a different set up it won't accomplish the task correctly.

    I'm trying to create a code where I can cut a cell based on certain criteria, and paste it into that same row number but in the A column. Offsetting won't seem to work because some of the text is in column b, some in c, and some in D. I was thinking I could create an if statement that has the following logic: If cell is in column B offset by (0,-1), if in column C offset by (0,-2), etc, etc.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Merged cells are the bane of programmers. In any case, something like?
    Sub Main()  Dim r As Range
      With Worksheets("New")
        Set r = .Range("B5:B21")
        r.Cut .Range(.Range("A" & r.Row), .Range("A" & r.Rows.Count + r.Row - 1))
      End With
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jul 2016
    Posts
    35
    Location
    Awesome, thanks Kenneth. This means I could run an if statement through for different text strings (include all possible text strings that could show up) and then place them in the correct column using r.Row?

  4. #4
    VBAX Regular
    Joined
    Jul 2016
    Posts
    35
    Location
    I'm just trying to figure out the absolute best way to automate this process for people using VBA.

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    As Kenenth says, merged cells are a mjor pain.
    Seriously consider exporting from Quickbooks in a different format and then opening the resultant file in Excel. See https://www.sleeter.com/blog/2014/02...reports-excel/
    We can help you with your further analysis of such files.

    I see also there's an option when exporting to Excel to create a csv file: http://www.accountingweb.com/technol...ports-to-excel
    This could be the best way.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    As p45cal said, exporting your data into csv might be the best approach as both programs can deal with that pseudo database file type.

    While you can use If()'s, Select Case may be the better choice. It just depends what your goals are using the data. A Range.Find() can find what columns key words are at.

    Of course providing an obfuscated simple csv and expected outcome file is a good way to get specific help. Click the Go Advanced button in lower right of a reply and then the paperclip icon in toolbar to Browse and Upload file(s).

  7. #7
    VBAX Regular
    Joined
    Jul 2016
    Posts
    35
    Location
    Ok, I don't have access to a freshly exported file right now, need to wait until I get that and I can attach it to show. Thanks for helping so quick though and I'll post it as soon as I have it.

    That CSV page might be the way to do it, especially if you can autorefresh the P&L data

  8. #8
    VBAX Regular
    Joined
    Jul 2016
    Posts
    35
    Location
    I'm going to just export it as a CSV from now on and create a macro to format it in the way I like. Thanks for the help guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •