Help with Macro

rwmill9716

Active Member
Joined
May 20, 2006
Messages
493
Office Version
  1. 2013
Platform
  1. Windows
This macro pulls sequential pairs of data in workbook "Raw Data", contrasting Col A there against the other 9 columns.

Workbook "Calculated Results" shows its last pair of data columns in Cols B and C. Row 7 data in Cols E through I are copied into Cols J through N for each sequential pair. The last (the 1-10 pair) is shown in yellow.

In looking at the data in Cols J through N, it's obvious that some of the pairs are incorrect (2nd, 3rd and 7th). What's wrong with the code?

How would I change the code to generate all possible pairs (45 with 10 columns of data), i.e., include those not contrasted against the 1st col in "Raw Data", the 2-3 pair?

How do I place my macro here so that contained in the normal coded box I see others using?




Sub Partiton_Pairs()
Dim LastCol As Long, Col As Long, LastRow As Long
Dim rData As Range

Application.ScreenUpdating = False
With Sheets("Raw Data")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rData = .Range("A1").Resize(LastRow, LastCol)
End With
With Sheets("Calculated Results")
For Col = 2 To LastCol
.Range("B6").Resize(LastRow).Value = rData.Columns(1).Value
.Range("C6").Resize(LastRow).Value = rData.Columns(Col).Value
.Range("B6").Resize(LastRow, 2).Sort Key1:=.Range("C7"), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Application.EnableEvents = False
Range("J" & Rows.Count).End(xlUp).Offset(1) = Range("E7").Value
Range("K" & Rows.Count).End(xlUp).Offset(1) = Range("f7").Value
Range("L" & Rows.Count).End(xlUp).Offset(1) = Range("G7").Value
Range("M" & Rows.Count).End(xlUp).Offset(1) = Range("H7").Value
Range("N" & Rows.Count).End(xlUp).Offset(1) = Range("I7").Value
Application.EnableEvents = True






Excel 2003
ABCDEFGHIJ
1AMC in CHMDACNin CHMDADN in CHMDBHMT in CHMDCAT in CHMDDAMP in CHMDDCH in CHMDH2O in CHMDHMD in CHMDHMI in CHMD
212345678910
3102.18980.6227210.6495089.681225125.04441481.3064.20234194.766571404.508
4103.513576.8382310.659.658118122.94611461.1094.14865294.751351403.865
570.9172810.6493759.635011121.36831457.2014.10733194.794551402.796
6101.564.510.6459.6119041221514.54.1194.8051424.5
759.9093310.6341739.588796124.22994.13810694.795821439.393
8110.355466.7746119.5656891592.3234.27484694.70161
974.6209610.5449389.542582141.42861595.3354.41055894.606531343.134
10121.515278.0910410.549.519475133.69651563.8774.45606294.574241351.486
Raw Data




Excel 2003
ABCDEFGHIJKLMN
1CorrelationPair
2ctrl p-0.1054812AMC in CHMDACNin CHMD
30.282809102.1891AMC in CHMDADN in CHMD
40.434564121.51520.54AMC in CHMDBHMT in CHMD
5-0.1056715AMC in CHMDCAT in CHMD
6AMC in CHMDHMI in CHMDCorrelationPair-0.0610716AMC in CHMDDAMP in CHMD
7110-0.968110AMC in CHMDHMI in CHMD0.14706617AMC in CHMDDCH in CHMD
81343.1340.25613504.107331AMC in CHMDH2O in CHMD
9121.51521351.486-0.1067919AMC in CHMDHMD in CHMD
101402.796-0.9677110AMC in CHMDHMI in CHMD
11103.51351403.865
12102.1891404.508
13101.51424.5
141439.393
15110.3554
16
Calculated Results
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
For the easy part of containing the code.

Without the *'s type in [*code*] then Enter to give yourself a space, then type [*/code*].
Copy and paste in between the two code tags.

Regards,
Howard
 
Last edited:
Upvote 0
Thanks, L, but I do not see two code tags. Is the first one "Code:"
 
Upvote 0
See my signature block about code tags.

Not sure I follow but notce that the code for copying the calculated values are referencing the ActiveSheet and not the With Sheets("Calculated Results")

Add periods e.g.
Code:
.Range("J" & Rows.Count).End(xlUp).Offset(1) = .Range("E7").Value
[COLOR=#ff0000].[/COLOR]Range("K" & Rows.Count).End(xlUp).Offset(1) = [COLOR=#ff0000].[/COLOR]Range("f7").Value
[COLOR=#ff0000].[/COLOR]Range("L" & Rows.Count).End(xlUp).Offset(1) = [COLOR=#ff0000].[/COLOR]Range("G7").Value
[COLOR=#ff0000].[/COLOR]Range("M" & Rows.Count).End(xlUp).Offset(1) = [COLOR=#ff0000].[/COLOR]Range("H7").Value
[COLOR=#ff0000].[/COLOR]Range("N" & Rows.Count).End(xlUp).Offset(1) = [COLOR=#ff0000].[/COLOR]Range("I7").Value

Or just this...
Code:
.Range("J" & Rows.Count).End(xlUp).Offset(1).Resize(, 5) = .Range("E7:I7").Value
 
Upvote 0
No it is not Code: that 's just the way shows up if done corectly, as you see with AlphaFrog's post. And read his signature block, he has an example and I have used it here exactly as it is written in his block.

Code:
your VBA code here

You do a [ type the word code and do another ]

For the bottom one do a [/ type the word code and do another ]

When it is posted you see Code: followed by the shaded box with your stuff in it and nothing below.

Somewhere there is a test post site but I can never find it when I want to.

Perhaps you could just try it here in your thread to get you going.

Howard
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,208
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top