Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Code work but a easier way to do this.

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Code work but a easier way to do this.

** 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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Code work but a easier way to do this.

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this code not work? John Keith[_2_] Excel Programming 2 February 15th 06 08:51 PM
Why Won't This Code Work???? TK[_3_] Excel Programming 2 September 15th 05 08:26 AM
Help getting code to work. Frank Stone Excel Programming 1 July 28th 04 10:01 PM
Code won't work? Joe 90 Excel Programming 3 October 2nd 03 04:26 AM
Why my code do not work : - ( Bob Phillips[_5_] Excel Programming 0 August 31st 03 01:27 PM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"