PC Review


Reply
Thread Tools Rate Thread

Code work but a easier way to do this.

 
 
=?Utf-8?B?VmljdG9yIFRvcnJlcw==?=
Guest
Posts: n/a
 
      11th Jun 2007
Hi to all. My code work nice but is a little long. I know that it could be
simplefy using value and other codes that I don't know. can anybody help
me?? I have to run this from column C to N. Here is the code.

Sub Run_Macro()

monthfree = Range("C7").Value
If monthfree = Empty Then
Call Execute

SightPurch = Range("A36").Value
Range("C7").Select
ActiveCell.FormulaR1C1 = SightPurch
InvoiceElite = Range("A37").Value
Range("C8").Select
ActiveCell.FormulaR1C1 = InvoiceElite
Unidentified = Range("A41").Value
Range("C12").Select
ActiveCell.FormulaR1C1 = Unidentified
Else

monthfree = Range("D7").Value
If monthfree = Empty Then
Call Execute

SightPurch = Range("A36").Value
Range("D7").Select
ActiveCell.FormulaR1C1 = SightPurch
InvoiceElite = Range("A37").Value
Range("D8").Select
ActiveCell.FormulaR1C1 = InvoiceElite
Unidentified = Range("A41").Value
Range("D12").Select
ActiveCell.FormulaR1C1 = Unidentified
Else

monthfree = Range("E7").Value
If monthfree = Empty Then
Call Execute

SightPurch = Range("A36").Value
Range("E7").Select
ActiveCell.FormulaR1C1 = SightPurch
InvoiceElite = Range("A37").Value
Range("E8").Select
ActiveCell.FormulaR1C1 = InvoiceElite
Unidentified = Range("A41").Value
Range("E12").Select
ActiveCell.FormulaR1C1 = Unidentified
Else
'AGAIN AND AGAIN UNTIL COLUMN "N"
End If
End If
End If


End Sub
 
Reply With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      11th Jun 2007
** untested air code **

Dim wks as Worksheet

Set wks = ActiveSheet

For c = 3 to 14 'columns C to N
If Len(wks.Cells(7,c).Value) = 0 Then
Call Execute

wks.Cells(7,c).FormulaR1C1 = wks.Range("A36").Value
wks.Cells(8,c).FormulaR1C1 = wks.Range("A37").Value
wks.Cells(12,c).FormulaR1C1 = wks.Range("A41").Value
' Exit loop after the first empty cell is encountered
Exit For
End If
Next c


You *could* also bracket the "For...Next" loop with a "With...End With"
construct:
With wks
....
End With
This would further simplify the code (and improve performance), but I chose
not to do that here for clarity (i.e., too much information at one time),
but feel free to look it up in VBA Help if you think you are ready for it.

HTH,



"Victor Torres" <(E-Mail Removed)> wrote in message
news:15F40D61-3B05-44FC-9D51-(E-Mail Removed)...
> Hi to all. My code work nice but is a little long. I know that it could
> be
> simplefy using value and other codes that I don't know. can anybody help
> me?? I have to run this from column C to N. Here is the code.
>
> Sub Run_Macro()
>
> monthfree = Range("C7").Value
> If monthfree = Empty Then
> Call Execute
>
> SightPurch = Range("A36").Value
> Range("C7").Select
> ActiveCell.FormulaR1C1 = SightPurch
> InvoiceElite = Range("A37").Value
> Range("C8").Select
> ActiveCell.FormulaR1C1 = InvoiceElite
> Unidentified = Range("A41").Value
> Range("C12").Select
> ActiveCell.FormulaR1C1 = Unidentified
> Else
>
> monthfree = Range("D7").Value
> If monthfree = Empty Then
> Call Execute
>
> SightPurch = Range("A36").Value
> Range("D7").Select
> ActiveCell.FormulaR1C1 = SightPurch
> InvoiceElite = Range("A37").Value
> Range("D8").Select
> ActiveCell.FormulaR1C1 = InvoiceElite
> Unidentified = Range("A41").Value
> Range("D12").Select
> ActiveCell.FormulaR1C1 = Unidentified
> Else
>
> monthfree = Range("E7").Value
> If monthfree = Empty Then
> Call Execute
>
> SightPurch = Range("A36").Value
> Range("E7").Select
> ActiveCell.FormulaR1C1 = SightPurch
> InvoiceElite = Range("A37").Value
> Range("E8").Select
> ActiveCell.FormulaR1C1 = InvoiceElite
> Unidentified = Range("A41").Value
> Range("E12").Select
> ActiveCell.FormulaR1C1 = Unidentified
> Else
> 'AGAIN AND AGAIN UNTIL COLUMN "N"
> End If
> End If
> End If
>
>
> End Sub



 
Reply With Quote
 
=?Utf-8?B?VmljdG9yIFRvcnJlcw==?=
Guest
Posts: n/a
 
      11th Jun 2007
George... YOU ARE THE BEST!!!! it works nice....
Thanks a lot



"George Nicholson" wrote:

> ** untested air code **
>
> Dim wks as Worksheet
>
> Set wks = ActiveSheet
>
> For c = 3 to 14 'columns C to N
> If Len(wks.Cells(7,c).Value) = 0 Then
> Call Execute
>
> wks.Cells(7,c).FormulaR1C1 = wks.Range("A36").Value
> wks.Cells(8,c).FormulaR1C1 = wks.Range("A37").Value
> wks.Cells(12,c).FormulaR1C1 = wks.Range("A41").Value
> ' Exit loop after the first empty cell is encountered
> Exit For
> End If
> Next c
>
>
> You *could* also bracket the "For...Next" loop with a "With...End With"
> construct:
> With wks
> ....
> End With
> This would further simplify the code (and improve performance), but I chose
> not to do that here for clarity (i.e., too much information at one time),
> but feel free to look it up in VBA Help if you think you are ready for it.
>
> HTH,
>
>
>
> "Victor Torres" <(E-Mail Removed)> wrote in message
> news:15F40D61-3B05-44FC-9D51-(E-Mail Removed)...
> > Hi to all. My code work nice but is a little long. I know that it could
> > be
> > simplefy using value and other codes that I don't know. can anybody help
> > me?? I have to run this from column C to N. Here is the code.
> >
> > Sub Run_Macro()
> >
> > monthfree = Range("C7").Value
> > If monthfree = Empty Then
> > Call Execute
> >
> > SightPurch = Range("A36").Value
> > Range("C7").Select
> > ActiveCell.FormulaR1C1 = SightPurch
> > InvoiceElite = Range("A37").Value
> > Range("C8").Select
> > ActiveCell.FormulaR1C1 = InvoiceElite
> > Unidentified = Range("A41").Value
> > Range("C12").Select
> > ActiveCell.FormulaR1C1 = Unidentified
> > Else
> >
> > monthfree = Range("D7").Value
> > If monthfree = Empty Then
> > Call Execute
> >
> > SightPurch = Range("A36").Value
> > Range("D7").Select
> > ActiveCell.FormulaR1C1 = SightPurch
> > InvoiceElite = Range("A37").Value
> > Range("D8").Select
> > ActiveCell.FormulaR1C1 = InvoiceElite
> > Unidentified = Range("A41").Value
> > Range("D12").Select
> > ActiveCell.FormulaR1C1 = Unidentified
> > Else
> >
> > monthfree = Range("E7").Value
> > If monthfree = Empty Then
> > Call Execute
> >
> > SightPurch = Range("A36").Value
> > Range("E7").Select
> > ActiveCell.FormulaR1C1 = SightPurch
> > InvoiceElite = Range("A37").Value
> > Range("E8").Select
> > ActiveCell.FormulaR1C1 = InvoiceElite
> > Unidentified = Range("A41").Value
> > Range("E12").Select
> > ActiveCell.FormulaR1C1 = Unidentified
> > Else
> > 'AGAIN AND AGAIN UNTIL COLUMN "N"
> > End If
> > End If
> > End If
> >
> >
> > End Sub

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Look up between 2 times over midnight - is there an easier way than recordset code? Evi Microsoft Access Form Coding 20 14th Apr 2008 02:25 AM
When queries fail in VBA code, then work manually, then work in code? AdmiralXizor Microsoft Access Queries 7 20th Jun 2007 12:10 AM
managed wrapper to native code.. code from 2003 does not work in 2005? Fred Heida Microsoft Dot NET 0 8th Mar 2006 04:09 AM
Categories should be easier to work with in Outlook =?Utf-8?B?UkI=?= Microsoft Outlook Discussion 1 18th Apr 2005 12:37 AM
Is there a easier way to avoid harmful html code? david Microsoft Dot NET 2 18th Nov 2003 08:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 AM.