VBA Macro To Move Data To Summary Sheet Based On ID's - Excel Help & Excel Macro Help
SEARCH ENTIRE SITE LOADING..

Excel Help & Excel Best Practices Forums

 

Proudly Affiliated With: Intelligent Converters & AnalyserXL <Affiliate Program & ExcelUser Affiliate>

 

SPECIALS PAGE FOR BARGAINS | FREE EXCEL TRAINING | FREE CUSTOM FUNCTIONS ADD-IN


Go Back Excel Help & Excel Macro Help > HELP FORUMS > EXCEL HELP
HOME Register Forum Help Calendar Search For Today's Posts Mark Forums Read

Reply

VBA Macro To Move Data To Summary Sheet Based On ID's

ANSWERS TO SIMILAR QUESTIONS
Add Data From Unknown Number Of Sheets To Summary SheetSummary Report Sheet From Data TableSummary Sheet Of DataMacro To Move From One Sheet To Another Based On ResponsesCategorizing data on monthly worksheets to Summary sheet



Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com

Create Excel dashboards quickly with Plug-N-Play reports.


 
Thread Tools Search this Thread
Old 2 Weeks Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
spitz7985 spitz7985 is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 4th November 2009
English is 1st Language: Yes
Posts: 4 -- Threads: 0
VBA Macro To Move Data To Summary Sheet Based On ID's

Hello,
I am having a very difficult time with this code. I have had several intro programming classes, but not with visual basic. I've noted the problem lines with comments below. The problems are probably very easy syntax error. I wouldn't be surprised if this code is not the most efficient way to go about this either, but like I said, I'm a noob. I've searched a lot, but have not had luck.

VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub list() Dim counter As Integer Dim counter2 As Integer Dim id As Double Dim id2 As Double Dim palletnum As Integer ActiveSheet. Name = "Pallet Detail" Sheets.Add ActiveSheet.Name = "Pallet Summary" Sheets("Pallet Detail").Select For Each z In Range("b2:b2000") id = Range(z).Offset(0, -1).Value 'the range(z) does not work id2 = Range(z).Offset(3, -1).Value 'the range(z) does not work If InStr((z.Value), "Count") Then counter = counter + 1 z.Cut Destination:=Sheets("Pallet Summary").Range("B" & counter) End If If id <> id2 Then palletnum = palletnum + 1 Set Sheets("Pallet Summary").Range("A" & counter) = palletnum 'this is a problem line End If Next For Each y In Range("c2:c2000") If InStr((y.Formula), " SUBTOTAL") Then counter2 = counter2 + 1 y.Cut Destination:=Sheets("Pallet Summary").Range("C" & counter2) End If Next End Sub
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
norie's Avatar
norie norie is offline
OzMVP
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 14th July 2004
English is 1st Language: Yes
Posts: 9,763 -- Threads: 21
Re: Range(variable) Syntax And Other Syntax Difficutly

Why are you using Range(z)?

Why not just z?

Why are you using Set here?
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Set Sheets("Pallet Summary").Range("A" & counter) = palletnum

Perhaps this?
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Option Explicit Sub CreateList() Dim y As Range Dim z As Range Dim id As Double Dim id2 As Double Dim counter As Long Dim counter2 As Long Dim palletnum As Long ActiveSheet.Name = "Pallet Detail" Sheets.Add ActiveSheet.Name = "Pallet Summary" Sheets("Pallet Detail").Select For Each z In Sheets("Pallet Detail").Range("B2:B2000") id = z.Offset(0, -1).Value 'the range(z) does not work id2 = z.Offset(3, -1).Value 'the range(z) does not work If InStr(z.Value, "Count") Then counter = counter + 1 z.Cut Destination:=Sheets("Pallet Summary").Range("B" & counter) End If If id <> id2 Then palletnum = palletnum + 1 Sheets("Pallet Summary").Range("A" & counter) = palletnum 'this is a problem line End If Next For Each y In Sheets("Pallet Detail").Range("C2:C2000") If InStr(y.Formula, " SUBTOTAL") Then counter2 = counter2 + 1 y.Cut Destination:=Sheets("Pallet Summary").Range("C" & counter2) End If Next End Sub
__________________
Boo!
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
spitz7985 spitz7985 is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 4th November 2009
English is 1st Language: Yes
Posts: 4 -- Threads: 0
Re: Range(variable) Syntax And Other Syntax Difficutly

Hey Norie,
Thanks a lot!!

That's probably the reason I couldn't find anything about Range(variable) in my google searches, because you don't need the range()!

As far as the "set sheets..." line, well, what you corrected it to is what I started out with and it does not work for me. It is now the only line in the code holding me up. I thought maybe the "set" would set that cell equal to the palletnum variable, but I have not had luck with or without it.
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
norie's Avatar
norie norie is offline
OzMVP
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 14th July 2004
English is 1st Language: Yes
Posts: 9,763 -- Threads: 21
Re: Range(variable) Syntax And Other Syntax Difficutly

How is that part not working?

You only use Set when you want to create a reference to an object eg a range, worksheet etc.
__________________
Boo!

Last edited by norie : 2 Weeks Ago at 06:13. Reason: Cos I can't type right.
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
spitz7985 spitz7985 is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 4th November 2009
English is 1st Language: Yes
Posts: 4 -- Threads: 0
Re: Range(variable) Syntax And Other Syntax Difficutly

Uh oh. I think my problem is much deeper then this single line.

I think my problem is my loop. First of all, I knew that it was hack job way of doing it, because I don't necessarily need to loop until b2000 (you programmers are going to hate me for this). I just went down that far because I knew b2000 would for sure include all of my data. I'm going to be using this macro on many spreadsheets of varying length. This type of loop was also the only way I knew how to set the z to each cell in the B column counting down one row each time the loop cycles (although I now am seeing that it's not working like I thought it was).

Bascially what I'm trying to do is pull all my count subtotals from a sheet and paste it in column B (stating "xxx Count") and C (stating the count value) on a new sheet that this macro is creating. This macro did do this, but the part with the id and id2 variables was supposed to also insert a value into column A of the new sheet, explanation below.

The spreadsheet I'm starting with has this information (this is for work):
(A)Pallet ID Number (B)useless number (C)-part number (D&E)- useless

There is a row for each box of each part, so there are many in a row with the same Pallet ID number and the same part number. There can also be multiple part numbers per pallet ID number. There are two blank rows after each pallet ID number before the next pallet ID number, so I need to compare the pallet ID number from the active row to the pallet ID number three rows down, and if it is different, I need to insert a pallet count on the new sheet that the macro creates in column A, counting from 1 to up to 30. I have the original sheet sorted by pallet ID and then by part number and have count subtotals after each part number (eventually I would like the macro to do this automatically as well, but I'm taking one step at a time here).

This is what I want the new sheet to look like:

(A)Pallet Number (count from 1 to up to 30)
(B)Part Number "Count" (statement)
(C)value of the count subtotal
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
spitz7985 spitz7985 is offline
I agreed to these rules
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows XP
Assumed Experience: Average (know many formulas)
Join Date: 4th November 2009
English is 1st Language: Yes
Posts: 4 -- Threads: 0
Re: Range(variable) Syntax And Other Syntax Difficutly

Alright guys, I rewrote my loop and i"m very happy with it. However, I still have a problem with one of the if statements. I don't know if you can use the following or not, so I just did it the ugly way so I could be sure, but it still doesn't work. I'm sure that my "id" and "id2" variables are working perfectly because I printed them out and I can see the condition happeneing that my non-working if statement is supposed to be testing for.

Not sure if you can do this:
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
If id <> id2 And id <> 0 And id2 <> 0 Then

My code:
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub list() Dim mycellA As Range Dim mycellB As Range Dim mycellC As Range Dim rangecounter As Integer Dim L As Double Dim L2 As Double Dim Bcounter As Integer Dim Ccounter As Integer Dim id As Double Dim id2 As Double Dim palletnum As Integer ActiveSheet.Name = "Pallet Detail" Sheets.Add ActiveSheet.Name = "Pallet Summary" Sheets("Pallet Detail").Select L = 1 rangecounter = 1 Do Until L = 0 And L2 = 0 rangecounter = rangecounter + 1 Set mycellB = Range("B" & rangecounter) id = mycellB.Offset(0, -1).Value id2 = mycellB.Offset(3, -1).Value Sheets("Pallet Summary").Range("E" & rangecounter).Value = id 'TEST LINE Sheets("Pallet Summary").Range("F" & rangecounter).Value = id2 'TEST LINE If InStr((mycellB.Value), "Count") Then Bcounter = Bcounter + 1 mycellB.Cut Destination:=Sheets("Pallet Summary").Range("B" & Bcounter) ' ***********THIS BELOW IS THE PROBLEM IF STATEMENT******************** If id <> id2 Then If id <> 0 Then If id2 <> 0 Then palletnum = palletnum + 1 Sheets("Pallet Summary").Range("A" & Bcounter) = palletnum Sheets("Pallet Summary").Rows(Bcounter + 1).EntireRow.Insert End If End If End If End If Set mycellC = Range("C" & rangecounter) If InStr((mycellC.Formula), " SUBTOTAL") Then Ccounter = Ccounter + 1 mycellC.Cut Destination:=Sheets("Pallet Summary").Range("C" & Ccounter) End If Set mycellA = Range("A" & rangecounter) L = mycellA.Value L2 = mycellA.Offset(1, 0).Value Loop End Sub
__________________
ADS BY OZGRID. FREE DOWNLOADS SmartVBA | SmartVB6 | CodeVBA | CodeVB6 | Code Generator Pro | TraderXL Pro Package. MORE..
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
norie's Avatar
norie norie is offline
OzMVP
 
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 14th July 2004
English is 1st Language: Yes
Posts: 9,763 -- Threads: 21
Re: Range(variable) Syntax And Other Syntax Difficutly

I think you might want to chuck some parentheses in there, your logical statement might not actually be doing what you want.

Perhaps something like this.
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
If (id <> id2) And (id <> 0) And (id2 <> 0) Then
I know that might seem a bit simple but without the parentheses you might actually find you are comparing the wrong things.
__________________
Boo!
Print [Post / Thread] Reply With Quote
Old 2 Weeks Ago
Dave Hawley's Avatar
Dave Hawley Dave Hawley is offline
Administrator
 
I'm a Spammer: NO
MS Office Version: 2007 English
Op System: Windows Vista
Assumed Experience: Above Average
Join Date: 24th January 2003
English is 1st Language: Yes
Location: Australia
Posts: 49,234 -- Threads: 15169
Re: Range(variable) Syntax And Other Syntax Difficutly

spitz7985, please consider those who search, You thread title SHOULD spell out what you are tryting to do, not what YOU THINK the answer is.
Print [Post / Thread] Reply With Quote
Reply Lifetime Upgrade To Ad Free Styles

   « PREVIOUS UserForm Causes Crash Upon Load/Show || Return Related Information From Another Workbook NEXT »
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 23:10.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ozgrid is Not Associated With Microsoft. Ozgrid Retains the Rights to ALL Posts and Threads