Code Loop Through Two Tables Checking And Altering

Nov 12, 2008

I have two tables of information. The first is a matrix with some distances. The second is a table of distribution. Ive been trying this for a long time now with limited success using a truth table but i've realised the only way to do this is in code. Ive got limited experience with this so please point me in the right direction.

Ive written some steps explaining what each table does here -

Step 1Check for lowest value B4:F4 in Table 1 (in example is 10)
Step 2Check corresponding column destination available capacity in table 2 (Example 500)
Step 3Distribute as much as possible from source in table 2 (500)
Step 4Reduce value in capacity line by value taken from source
Step 5If some source remains move back to table 1 and find next nearest column Dest
Step 6Repeat step 2 until all source is gone in row
Step 7 Check for lowest value B5:F5 in Table 1
if run out of capacity at all sites stop code
etc
until Table 1 column B is empty

Ive posted a spreadsheet with some before and after tables in it aswell. Its very small and formatted o its easy to see whats happening.

View 14 Replies


ADVERTISEMENT

If Loop Checking The Formatting Of Cells

Feb 10, 2009

I am having trouble with several IF..THEN..ELSE loops in my code, all of which are pritty much the same. I need to find rows that are formatted in a certain way, in the example below this is a clear background and Black text. I know the loop works because i have tested it without colours on a test workbook, and i know the colours are correct, but it keeps skipping over the condition, regardless of the outcome. All the variables shown are declared correctly before the loop is entered.

View 2 Replies View Related

Loop Checking And Moving Data If Cell Is Not Empty

Mar 12, 2007

in writing a loop that will check a number of cells to see if it is emtpy, if it is not, then run the macro. If the cells are not empty it will copy the data in that row and paste it to another sheet and delete that line. If it hits a cell that is empty, i want it to skip that row and move on to the next row.

here is the macro that moves the data.
Sub movedata()

Range("A1:H1").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("A1").Select
Sheets("Sheet2").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
Sheets("Sheet1").Select
End Sub

View 9 Replies View Related

VBA In Constant Loop When Try To Refresh Other Pivot Tables

Jul 18, 2012

I have this code in an active worksheet that works with the exception that when I try refresh other Pivot Tables with the file that it goes into a constant loop.

Private Sub Worksheet_Change(ByVal Target As Range)
'
' Update the pivot table on this worksheet if data in columns A or B is changed
'
If (Target.Column = 1) Or (Target.Column = 2) Then
ActiveSheet.PivotTables(1).RefreshTable
End If
End Sub

View 2 Replies View Related

Loop Through Array In VBA To Refresh Pivot Tables

Jul 24, 2014

I'm hoping to automate some pivot table refreshes. I've got a dozen pivot tables on a sheet all with different numbers. I'm hoping I can write a code that loops through the pivot table names and runs the refresh. Here is the code as it is right now. I've essentially copied, pasted, and changed the name of the pivot table for the refresh.

I would like to create an array in vba (22,21,20,19,18...) that renames the PivotTable and runs the code.

sub Refresh ()
Dim pt4 As PivotTable
Dim Field4 As PivotField
Dim NewCat4 As String

Set pt4 = ActiveSheet.PivotTables("PivotTable22")

[Code] ..........

View 3 Replies View Related

Checking References Automatically Through Code?

May 4, 2009

I have an excel add-in that has got few macros which require two references,

1) Microsoft Word 12.0 object library
2) Microsoft Internet Controls

I have checked both these references and the macros are running perfectly on my PC. but when I distribute this add-in, sometimes the references are checked but sometimes it gives an error and the user is required to check the reference again.

Can i use some code to automatically check these two references. or is there some other easier way to get rid of this error.

View 8 Replies View Related

Code For Checking If A Sheet Exists

May 24, 2006

I need a line of code that will display a message box if a specific sheet does not exist. eg. If sheet called "ThisSheet" does not exist, then display the message "Not here". I've been struggling with this one!

View 3 Replies View Related

Insert A Row In 2 Tables With VBA Code

Apr 18, 2014

I am trying to insert via a command button a new row in 2 different tables but I am finding some difficulties . I have attached an excel sheet as example.

View 3 Replies View Related

Delete Query Tables Macro Code

Aug 14, 2008

I am currently working on a project that uses Excel to parse a .txt document. Its working quite well for me. It functions by having two worksheets. In the first worksheet I use the " import external data" menu to import my .txt file. In another worksheet I have set up fields that show only the important information from the .txt file and leave the junk behind.

I’m looking to improve the functionality of this by adding a button to automatically clear the data in the first worksheet so that new data can be added quickly.

I have searched the forum and found a couple of threads on "QueryTables". After reading up on those, I have made a simple button with the following code.

Sheets("Sheet1"). Cells.Clear
Sheets("Sheet1").QueryTables.Item(1).Delete

After I load a .txt file and parse it using the formulas set up, I copy my needed information and then press this button. The cells clear, and the QueryTables are "reset" (maybe not the right word). Now a different .txt file can be imported and the process starts again.

The problem I am having is that. If there is no "QueryTables.Item(1)" to delete, I get a run time error. (Run-time error '9': Subscript out of range).

Would anyone know how to make my button conditional to having a "QueryTable" active? I.E. If I press it when there is no data loaded it doesn't do anything or give me that error.

View 4 Replies View Related

VBA Code For Showing Detail From Pivot Tables Into Different Sheets

Dec 21, 2011

a query as i'm not too good with vba codes but can record macros but not for what i need.

I have got a pivot table which has about 200 rows. In Column A is the provider and in column B is the total number of people.

I now need to create a sheet per provider and the manual way to do is to double-click on the numbers.

Is there a code that would this automatically?

View 9 Replies View Related

Altering Data On Chart With Vba?

May 21, 2013

I have a very large workbook, too big to cut down and upload . In it I have some code which selects a graph and sets the data on the graph to an arbitary number, Unfortunately, I get a "Method 'Xvalues' of object 'Series' failed" error when I run it (although not every time). The relevant part of the code is below. Prior to the code below, different sheets are selected and variables moved around, then this part of the code hides the other sheets leaving the calculation page visible.

The graph is on a log-log scale, but I don't think that is particularly important. The data series are named as various things (e.g. baseline, reference, measurement) though but there are only ever two on the graph (I just rename them later on and change the data).

VB:
'open calculation page and hide survey results and archive pages
With Worksheets("Calculation Page")
.Visible = True: .Select

[Code]....

View 9 Replies View Related

Altering Parameters For IF Formula?

Mar 31, 2014

I need to modify the following formula,

=IF(G5=-105,-105,-G5-IF(ABS(G5)>251,40,IF(AND(ABS(G5)>221,ABS(G5)<251),30,
IF(AND(ABS(G5)>180,ABS(G5)<221),20,IF(AND(ABS(G5)>=100,ABS(G5)

[Code].....

View 10 Replies View Related

VBA Code To Auto-expand Columns When Pivot Tables Refresh

Mar 30, 2013

I have 2 drop downs that when changed, auto refresh all pivot tables. My problem is getting the columns to auto-adjust based on the refresh or change of the data in the pivot table. Listed below the code I have thus far for the auto-refresh on pivot tables. How to auto expand all columns simultaneously.

The pivot tables are based off of tables on a different sheet(TOS Tables). So the code listed below is in the table sheet, not the pivot table sheet (TOS Customer Level). So followup question will be, which sheet to put the auto-expand columns code?

VB:
Private Sub Worksheet_Calculate()
'If data on this worksheet changes, refresh the pivot table
Sheets("TOS Customer Level").PivotTables("PivotTable2").RefreshTable
Sheets("TOS Customer Level").PivotTables("PivotTable5").RefreshTable
End Sub

View 3 Replies View Related

Macro/Code Required For Calculations Base On Pivot Tables Sum

Jan 29, 2009

What I required is either a Macro or Code for formulas in column 'F' in the attached spreadsheet that correspond to the SUM of each description and divided by 37.5 e.g. in F10 the formula should be =D10/37.5 the formula should be F12 D10/37.5 and so on all the way down the Pivot table

My problem is as the amount data increases on the Data Tab the formulas in column 'F' will become out of line with the corresponding Sum of each description so I guess I need some code or formula that check every time the Pivot table is refreshed.

View 3 Replies View Related

Altering Macro To Read On Another Sheet?

Mar 26, 2013

I have come across another stumbling block with VBA (new on VBA and slowly taking baby steps). I have a macro that reads and deletes all duplicates on the files i work on. However I need this to read and do the job on 2 sheets at the sametime (sheet 2 and sheet 3). Below is the macro which does work fine on a different workbook. How would I integrate this into my new sheet to do 2 jobs at once?

VB:
Sub delduprows()
Dim m As Integer, j As Integer
Dim n As Long, i As Long

[Code]....

View 1 Replies View Related

SpinButton Altering Adjacent Cell?

Jun 12, 2014

I have a spinbutton on a userform. Here is the section of code for SpinUp:

[Code]....

Normally, I wouldn't hard code an address in like this, but I was given a last minute project to present on Monday, so it's down,dirty, and quick. Anyways, the adjacent cell "O7" has a formula referencing another page. When I spin the spinner it activates the correct cell (and continues to do so as long as I press the button), but here's the wierdness: cell "07" formula disappears, leaving the existing value in it. It's like it copy pastespecial values.

I've stepped through the code and it's not referencing any other procedure. It happens on this line:

[Code] ....

View 1 Replies View Related

Altering Formula To Read An <= Query

Sep 4, 2007

In cell AD17, I have a formula that returns the number of days or draws(Skips), since the number in cell AD2 has been drawn. The following cells AD18.......... returns the next skip and continues untill all the hits( AD3), are accounted for. My question, Can the formulas be altered to read a "

View 9 Replies View Related

Altering Variables Without Addressing The Name Directly

Jul 18, 2006

how does one alter a variable without referring to it directly? Eg. One has a combo box (CboPNum) with values from 1 to 20 and textboxes (TxtN1 to TxtN20). Upon selecting a value from the CboPNum dropdown, the background of the corresponding TextBox should be changed. I’ve tried to create something that joins the string “TxtN” and the CboPNum value:

ThisTextBox = “TxtN” & CboPNum.Value
ThisTextBox.Background = Black

But this quite correctly gives the error “Object required”… What do you guys recommend?

View 3 Replies View Related

Altering Cells Automatically With One Cell Input

Apr 3, 2008

i have on sheet one a cell that requires an order number ( e.g something like j2345a ) what i would like to do on sheet 2 cell c10 i would like to extract the letter after the 4 figures so that what i would see in that cell is j2345.

what i should add is that the letter after the four numbers isnt always an "a" so it could be any letter that needs to be removed

i also need cell c10 on sheet 2 to remain empty if there is nothing entered in cell e8 of the first sheet

View 12 Replies View Related

Input Symbol Without Altering Content Of Cell?

Dec 28, 2012

I have a column ful with numbers and would like to add an h (hour) after every number. I found that it is possible for valuta (dollar sign). Is there a way for random symbols that are not in the valuta list?

View 3 Replies View Related

Dynamically Altering Sheets From A Master Sheet

Apr 17, 2007

I have a workbook with four worksheets. Sheet1 is the master. On sheet one there is information in a 10x10 table. The first column of the table contains a status of "No, Maybe, Yes." A record will start with a status of No and move to Maybe and then yes. What I want to do is be able to dynamically fill sheet2-sheet4 with information from the master. If the status is "Yes" move that row to sheet2. If the status is "no" move that row to sheet 3. Etc. Further complication that is depending on status, I want specific columns from the master, not necessarily all of them.

View 2 Replies View Related

Compare Two Spreadsheets Altering 2nd One Based On Contents Of The First

Jul 6, 2007

I have a master spreadsheet containing 4 relevant fields, 'Manufacturer', 'Product', 'Version' and 'Type'. This contains all possible variations of 'manufacturer', 'product' and 'version' that can occur in the organisation.
The type field shows how the particular item is going to be processed, either 'automated', 'manual' or 'non'

This is a computer generated spreadsheet, apart from the 'Type' field which we've entered for each one individually, as are the user spreadsheets which dont yet have the 'type' field.

This is a large list of around 7000 items

I then have a multiple spreadsheets (one for each user, totaling around 1200) that has a list of a couple of hundred items that are relevant to the user which contains 'manufacturer', 'product' and 'version'.

i need to sort these out quickly by comparing the sheet to the master spreadsheet so where 'manufacturer', 'product' and 'version' match up with the masters record it automatically removes the the 'non' type of item from the user sheet and placing either 'automated' or 'manual' in a new 'type' filed where appropriate

View 3 Replies View Related

Altering A Existing Formula For Converting Bond Prices

Mar 31, 2009

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

Ok i have a formula that i use to convert bond prices, which are in 32nds to numbers that excel can understand. I use the formula:

=LEFT(F7,FIND("-",F7)-1)+SUBSTITUTE(RIGHT(F7,LEN(F7)-FIND("-",F7)),"+","")/IF(RIGHT(RIGHT(F7,LEN(F7)-FIND("-",F7)),1)="+",64,32)

This allows me to type 101-16 in and excel recognizes this as 101.5

My problem is that my data I am copying into the sheet is often in 1/8ths. So the price will come in as 101-272, which means 101-27 and 2/8 (or 1/4).

I admittedly dont understand this formula and just use. Can someone help me tweak it to recognize the third digit?

View 11 Replies View Related

Adding Advanced Filter Criteria Without Altering Pivot

Feb 8, 2012

At work, I have a workbook with multiple tabs that contain lists. Each tab has a corresponding Pivot Table.

There is a business requirement that a user can specify a name, which filters the data. For the sake of simplicity use this for an example

Column Headers: First_Name ; Last_Name; Age
Row 1: Johnny; Bravo; 29
Row 2: Shane; Falco; 34
Row 3; Bobby; Shane; 15

The user specifies "Shane" as the filter in another pre-determined Cell (D1). Using advanced criteria, I need to find all rows that have Shane in either First_Name or Last_Name. The only way I know how to do that is inserting two rows and adding criteria:

First_Name ; Last_Name; Age
=D1; ;
;=D1;
Johnny; Bravo; 29
Shane; Falco; 34
Bobby; Shane; 15

With Criteria Range = "A1:B3"

This is problematic because my Pivot tables now include 5 rows of data.

View 3 Replies View Related

Convert First Letter Of String To Capital Without Altering Formatting

Nov 17, 2009

Convert the first letter of a string to a capital without altering the rest of the strings format.

example: the activecell contains the string a1st (lowercase a, superscript 1st)

how can i achieve this in VBA?

Additionally, is it also possible to convert all of a string to capitals except the superscript characters

View 9 Replies View Related

Excel 2010 :: Creating Multiple Tables In VBA And Referring To Newly Created Tables?

Jul 1, 2013

Using Excel 2010. I'm writing a macro that sets up a workbook to be used for estimating at the beginning of a project. In the code I need to create multiple tables (formerly known as "lists") in the workbook. Then later in the code I need to refer back to those newly created tables. Currently, the code that creates the table is part of a loop that creates the table on many different worksheets. The problem of course, is that I have to name the Table, and then it won't create a table of the same name on the next sheet. Then, later in the code, I need to make adjustments to the table that was just created before looping to the next sheet.

Is there a way to create a table without giving it a constant name? Or by giving it a name that builds off of other info in the sheet? For example, I would be good with the naming the table after the sheet name: "Sheet1_Table" or such.

Code:
Sub Auto_Open()
'
Dim sht As Worksheet
If Range("A1") = 1 Then

[Code].....

View 2 Replies View Related

Loop With Below Code

Nov 10, 2008

Loop with below code. I have the below code:

View 2 Replies View Related

VBA Code To Loop To The Next Row Down

Dec 7, 2009

I just need to get it to loop down to the next row

Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
With ActiveSheet
Set rng = .Range("B1:AC1")
For Each cel In rng
x = x & cel.Value
Next
.Range("a1").Value = x
End With
End Sub

View 9 Replies View Related

Loop Code Through Certain Worksheets?

Nov 15, 2013

I am trying to loop the following code for a total of 15 worksheets without copying and pasting that same code 14 more times for each worksheet. Right now it is only executing the code on the "CAN" tab. Is there a way to make it loop where indicated below?

The 15 worksheets are:
CAN
USA
ASG
Gallia

[Code]......

View 3 Replies View Related

VBA - Trying To Loop Code Until Last Row Of Column

Feb 24, 2012

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim rw As Integer
Dim LastRow As Integer
LastRow = Sheet8.Range("B16:B300").End(xlUp).Row
For rw = 16 To LastRow

[Code] ........

Cannot get the loop to run. I am trying to make it so the loop will stop when it reaches the last non empty cell.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved