Macro - Multiple Variable

MotaA

New Member
Joined
May 10, 2010
Messages
2
Hey Guys

I need to create a macro that can count different columns from a huge Data Base and then save each result in a specific cell in another file.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
I have more than 70 different columns to be counted and so, I do not want to create more than 70 variables (like Result1, Result2, Result3…Result70 etc…)<o:p></o:p>
My question is: How to create a unique variable like (Result(N), where (N), that could:<o:p></o:p>
ð Count the first column based in a multiple criteria, save the result in a cell, clean-up the value from the variable and then count another column?<o:p></o:p>
<o:p> </o:p>
See following part of my initial code:<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Dim Results1 As Long, Results2 As Long……Results70 as long<o:p></o:p>
Dim Linha2 As Integer<o:p></o:p>
Dim I As Integer<o:p></o:p>
<o:p> </o:p>
Linha2 = 1<o:p></o:p>
<o:p> </o:p>
Do While Sheets(“PPV”).Cells(Linha2, "C") <> ""<o:p></o:p>
Linha2 = Linha2 + 1<o:p></o:p>
Loop<o:p></o:p>
<o:p> </o:p>
Linha2 = Linha2 - 1<o:p></o:p>
For I = 1 To Linha2<o:p></o:p>
<o:p> </o:p>
If Sheets(“PPV”).Cells(I, "F").Value < 0 Then<o:p></o:p>
If UCase(Cells(I, "AP").Value = "Cardinal Health") Then<o:p></o:p>
Cells(I, "F").Value = Cells(I, "F").Value<o:p></o:p>
<o:p></o:p>
Results1 = Results1 + Cells(I, "F").Value<o:p></o:p>
Sheets(“DATA”).Range("E6") = Results1<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
<o:p> </o:p>
If Sheets(“PPV”). Cells(I, "F").Value < 0 Then<o:p></o:p>
If UCase(Cells(I, "AP").Value = "GEA") Then<o:p></o:p>
Cells(I, "F").Value = Cells(I, "F").Value<o:p></o:p>
Results2 = Results2 + Cells(I, "F").Value<o:p></o:p>
Sheets(“DATA”).Range("E7") = Results2<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Thanks<o:p></o:p>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Re: Macro - Multiple Varaible

I'm not sure what you are trying to do exactly, but what you are describing is an array:

Code:
Sub Test()
Dim Result (0 to 3) as Integer
Result(0)=12
Result(1)=15
Result(2)=20
Msgbox Result(1)
End Sub
 
Upvote 0
Re: Macro - Multiple Varaible

Simple but efficient.
It's exactly what I was trying to do.

Thanks!
 
Upvote 0
Re: Macro - Multiple Varaible

I bet you can improve a lot on that code and similar code you are writing, but there's not enough information to elaborate on that.

What is this supposed to be?

Rich (BB code):
If UCase(Cells(I, "AP").Value = "Cardinal Health") Then

Don't you mean:

Rich (BB code):
If UCase(Cells(I, "AP").Value) = "CARDINAL HEALTH" Then

(the brackets are also wrong I think).

What does this do?

Rich (BB code):
Cells(I, "F").Value = Cells(I, "F").Value

Does it overwrite a formula?

Wigi
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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