473,668 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro that changes a particular column in pivot table.

19 New Member
Hi,

I'm executing Excel macros with VB as my front end
In my excel sheet...
i have pivot tables...
I need a macro that would change the particular column in the pivot table (say col K of the sheet ) . Change col K value from 1 to 0

I have 5 worksheets in one workbook.
On 3 worksheet i have to perform these operations....

can someone guide me
Aug 15 '07 #1
2 1753
kadghar
1,295 Recognized Expert Top Contributor
Hi,

I'm executing Excel macros with VB as my front end
In my excel sheet...
i have pivot tables...
I need a macro that would change the particular column in the pivot table (say col K of the sheet ) . Change col K value from 1 to 0

I have 5 worksheets in one workbook.
On 3 worksheet i have to perform these operations....

can someone guide me
Use workbooks, worksheets, cells, range and value.
Lets say you have 3 books and you want to write "hello" in column K from the row 1 to 10 in the 1st, 3rd and 5th sheets of the first and second workbook.

Expand|Select|Wrap|Line Numbers
  1. sub writeHello()
  2. dim i as integer
  3. dim j as integer
  4.  
  5. for i = 1 to 2
  6.      for j = 1 to 5 step 2
  7.           for n = 1 to 10
  8.                workbooks(i).worksheets(j).cells(n,11).value = "hello"
  9.           next
  10.      next
  11. next
  12. end sub
the range option is also useful, lets say you want to copy "A1:B5" in the first worksheet and paste it into a sheet called "PasteHere" in C5

Expand|Select|Wrap|Line Numbers
  1. Sub RangeTest()
  2. with worksheets(1)
  3.      range(.cells(1,1), .cells(5,2)).copy
  4. end with
  5. worksheets("PasteHere").cells(5,3).pastespecial -4163
  6. 'Note that -4163 is equivalent to the xlpastevalues (or something like that) since 
  7. 'its that constant's real value.
  8. end sub
Well, hope that helps
Aug 15 '07 #2
BSB
19 New Member
thank u....it worked



Use workbooks, worksheets, cells, range and value.
Lets say you have 3 books and you want to write "hello" in column K from the row 1 to 10 in the 1st, 3rd and 5th sheets of the first and second workbook.

Expand|Select|Wrap|Line Numbers
  1. sub writeHello()
  2. dim i as integer
  3. dim j as integer
  4.  
  5. for i = 1 to 2
  6.      for j = 1 to 5 step 2
  7.           for n = 1 to 10
  8.                workbooks(i).worksheets(j).cells(n,11).value = "hello"
  9.           next
  10.      next
  11. next
  12. end sub
the range option is also useful, lets say you want to copy "A1:B5" in the first worksheet and paste it into a sheet called "PasteHere" in C5

Expand|Select|Wrap|Line Numbers
  1. Sub RangeTest()
  2. with worksheets(1)
  3.      range(.cells(1,1), .cells(5,2)).copy
  4. end with
  5. worksheets("PasteHere").cells(5,3).pastespecial -4163
  6. 'Note that -4163 is equivalent to the xlpastevalues (or something like that) since 
  7. 'its that constant's real value.
  8. end sub
Well, hope that helps
Aug 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5321
by: pw | last post by:
Hi, I have month names (coming from a field in a table) as the column heading in an Access 97 crosstab query. It is being sorted alphabetically. This will not do. The only way that I know to get around it is to use month numbers instead, but I'd rather have the names appear. Any ideas?
6
13418
by: steve lord | last post by:
Greetings all, I have a macro that should add a column to a table if the column doesn't already exist. Using the macro condition, how can I test for whether a specific column name in a specific table exists? TIA for any help, Steve Lord
3
9235
by: Lee | last post by:
I have a crosstab query that lists the number of patients(DECnum)by County. County is my Row Heading. Currently, the Column heading is Age in months, which is set at one month intervals. I would like to reduce the number of columns by specifying age groupings. For example, Column 1 shoud cover ages 0 to 6 months, Column 2: 7 to 18 months, column 3: 19 -29 months and column 4: 30-36 months. I know I need to insert code for Pivot format,...
12
4766
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know how to create auto_increment. here is my try:
5
4532
by: Pourya99 | last post by:
Hello, I have an Access Data Access Page which has a pivot table. The data source of the pivot table is a SQL database table. The data in the pivot table itself is not a problem. I have a text box below the pivot table. Let's say the pivot table has: First Name, Last Name, and Address. When I click on a record in the pivot table, I want the Address for that selected record to be displayed in the textbox below. What I have currently...
2
3174
by: MMak12 | last post by:
Hi, I have generated pivot table using perl and getting data from database. I have two rows, pivot table automaticaly calculate the total for each row. I want remove the total for one row and keep the other one. If some one has done this please let me know and also how to highlight row in the table.Any documentation or code snippet will be help full. Thanks
0
3471
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined one which creates a pivot table and sorts it into different fromats. Here is the code, can any body help? Sub Update_Land_Actuals() On Error Resume Next If InputBox("Enter password to continue", "Centex Homes") <> "***" Then Exit Sub...
1
3116
by: goldxr | last post by:
Hi, Has anyone come across a print report macro that updates any changes you make on a main form? The issue I have is I have a pivot chart called It is a sub form in the main form I have a cammand button that prints the report
1
1840
by: yimma216 | last post by:
I am working on a macro and try to convert data in a pivot table to a flat data table automatically. Eg. Apple Oragne Pear Tim 1 2 3 Joe 2 3 4 Elle 6 7 8 into
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.