Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 118
Default Simplifying VBA code

Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?

range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)

Thanks for any assistance
Michael M
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 118
Default Simplifying VBA code

Thanks Don
That's a little left field, but I'll try anything to improve by VBA knowledge
Regards
Michael M

"Don Guillett" wrote:

maybe where col F =6

for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?

range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)

Thanks for any assistance
Michael M




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 694
Default Simplifying VBA code

Don,

The original request was for columns F,H and I and therfore a step in the
for loop is required:

for i = 6 to 10 step 2
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Don Guillett" wrote:

maybe where col F =6

for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?

range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)

Thanks for any assistance
Michael M




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Simplifying VBA code

But wouldn't this act on columns F, H and J ?

Pete

Martin Fishlock wrote:

Don,

The original request was for columns F,H and I and therfore a step in the
for loop is required:

for i = 6 to 10 step 2
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Don Guillett" wrote:

maybe where col F =6

for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?

range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)

Thanks for any assistance
Michael M





  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 694
Default Simplifying VBA code

Pete

Thanks for pointing that out.

It makes the code a little more difficult to simplify, I would in this case
move it to a seperate subroutine and call them sepeately.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Pete_UK" wrote:

But wouldn't this act on columns F, H and J ?

Pete

Martin Fishlock wrote:

Don,

The original request was for columns F,H and I and therfore a step in the
for loop is required:

for i = 6 to 10 step 2
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Don Guillett" wrote:

maybe where col F =6

for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i

--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?

range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)

Thanks for any assistance
Michael M





  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Simplifying VBA code

Modifying Don's code slightly, you could do this:

for i = 6 to 9
If i = 7 Then i = 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


Although I don't like modifying the loop control variable.

Pete

On Jan 24, 11:11 am, Martin Fishlock
wrote:
Pete

Thanks for pointing that out.

It makes the code a little more difficult to simplify, I would in this case
move it to a seperate subroutine and call them sepeately.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.



"Pete_UK" wrote:
But wouldn't this act on columns F, H and J ?


Pete


Martin Fishlock wrote:


Don,


The original request was for columns F,H and I and therfore a step in the
for loop is required:


for i = 6 to 10 step 2
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Don Guillett" wrote:


maybe where col F =6


for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and education, is
there a simpler way to write it ?


range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)


Thanks for any assistance
Michael M- Hide quoted text -- Show quoted text -


  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default Simplifying VBA code

A novel (to me) approach. I kind of like it. Just tested with no bad result.
Got 6,8,9

Sub modifyloop()
For i = 6 To 9
If i = 7 Then i = 8
MsgBox i
'Cells(12, i).Copy
'Range(Cells(13, i), Cells(lrow - 1, i)).PasteSpecial (xlPasteFormats)
Next i
End Sub

--
Don Guillett
SalesAid Software

"Pete_UK" wrote in message
oups.com...
Modifying Don's code slightly, you could do this:

for i = 6 to 9
If i = 7 Then i = 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


Although I don't like modifying the loop control variable.

Pete

On Jan 24, 11:11 am, Martin Fishlock
wrote:
Pete

Thanks for pointing that out.

It makes the code a little more difficult to simplify, I would in this
case
move it to a seperate subroutine and call them sepeately.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.



"Pete_UK" wrote:
But wouldn't this act on columns F, H and J ?


Pete


Martin Fishlock wrote:


Don,


The original request was for columns F,H and I and therfore a step in
the
for loop is required:


for i = 6 to 10 step 2
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Don Guillett" wrote:


maybe where col F =6


for i = 6 to 8
cells(12,i).copy
range(cells(13,i),cells(lrow-1,i)).PasteSpecial (xlPasteFormats)
next i


--
Don Guillett
SalesAid Software

"Michael M" wrote in message
...
Hi All
The following code works fine, but for my information and
education, is
there a simpler way to write it ?


range("F12").Copy
range("F13:F" & lrow - 1).PasteSpecial (xlPasteFormats)
range("H12").Copy
range("H13:H" & lrow - 1).PasteSpecial (xlPasteFormats)
range("I12").Copy
range("I13:I" & lrow - 1).PasteSpecial (xlPasteFormats)


Thanks for any assistance
Michael M- Hide quoted text -- Show quoted text -




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
VBA: For Count, when count changes from cell to cell LenS Excel Discussion (Misc queries) 18 January 4th 07 12:53 AM
Cell value not recognized by code. Brady Excel Discussion (Misc queries) 8 December 21st 06 02:56 AM
Text formatting Kace Excel Worksheet Functions 1 September 18th 06 08:28 PM
VLOOKUP for Zip Code Ranges JerseyJR Excel Worksheet Functions 2 September 6th 05 06:37 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM


All times are GMT +1. The time now is 05:22 AM.

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

About Us

"It's about Microsoft Excel"