Minggu, 08 Januari 2017

Re: [ExcelVBA] cut and paste cells with code

 

There is always code that can do anything. I would go about it as follows:
Problem statement – copy subtotals only to column D, maintaining their current row.

Code:
Dim i as integer
Dim LastRow as Integer

‘Prompt user to place cursor in Column C or Column D

‘Count number of rows in current column

‘Conditional copy and paste special – values only
For i = 2 to LastRow
If left(Range(CurrentColumn & i).formula = subtotal then
Copy
PasteSpecial ValuesOnly
Else
End If
Next i 

The SpecialCells function may also be useful if your SubTotals are the only formulas in Columns B and C. See http://www.ozgrid.com/VBA/special-cells.htm for examples. Will save you from the looping, but I didn’t know if you had other formulas.



Paul


From: "ExcelVBA@yahoogroups.com" <ExcelVBA@yahoogroups.com> on behalf of "ExcelVBA@yahoogroups.com" <ExcelVBA@yahoogroups.com>
Reply-To: "ExcelVBA@yahoogroups.com" <ExcelVBA@yahoogroups.com>
Date: Monday, 9 January 2017 at 03:15
To: "ExcelVBA@yahoogroups.com" <ExcelVBA@yahoogroups.com>
Subject: [ExcelVBA] cut and paste cells with code

 

I'm trying to cut and paste cells in a spreadsheet that correspond to subtotals. The subtotals and corresponding labels are multi-level (2 levels). There are two scenarios that I am trying to work with:

  1. select the subtotal labels in column B (7 labels) and cut and paste to the same row in column D
  2. select the subtotal labels in column C (24 labels) and cut and paste to the same row in column D

Is there any code that can accomplish this?

The file that I am working with is dynamic (monthly report) but the subtotal labels are constant. I already have code in place to format the data but I want to arrange the cells containing subtotal labels to be aligned in the same column (D) which they are not when the data is imported from the database. If it helps I can attempt to upload an example of the file.


Thanks


__._,_.___

Posted by: Paul Vermeulen <paul.vermeulen@vulcantech.com.au>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Posting Komentar