#1   Report Post  
Posted to microsoft.public.excel.misc
TimmerSuds
 
Posts: n/a
Default Macro help


I have the following macro that inserts a new column and pastes SLS into
the new column. The way the macro is currently set is to paste it into
rows 2-33.

I need it to paste SLS into all rows in Column G that are not blank
(this can vary from 1 to 500 rows).

Here's the current macro. I'd appreciate any advice
Thanks!

Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
ActiveCell.FormulaR1C1 = "SLS"
Range("C1").Select
Selection.Copy
Range("C2:C33").Select
ActiveSheet.Paste


--
TimmerSuds
------------------------------------------------------------------------
TimmerSuds's Profile: http://www.excelforum.com/member.php...o&userid=35596
View this thread: http://www.excelforum.com/showthread...hreadid=553818

  #2   Report Post  
Posted to microsoft.public.excel.misc
Mallycat
 
Posts: n/a
Default Macro help


TimmerSuds Wrote:
I need it to paste SLS into all rows in Column G that are not blank
(this can vary from 1 to 500 rows).

Not Blank? or blank? How will you know how many rows there are? you
need a column that you know will have data in the last row. I'll
assume that Column A has data in every row. Also, is the data in col G
before you insert the new column or after? You will need to swap the
code around if it is before.


Sub UpdateSLS()
Dim myRange As Range
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Value = "SLS"
Range("C2:C33").Value = "SLS"
LastRow = Range("A600").End(xlUp).Row
myAddress = "G1:G" & LastRow
Set myRange = Range(myAddress)
For Each cell In myRange
If cell.Value < "" Then cell.Value = "SLS"
Next cell

End Sub


--
Mallycat
------------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...o&userid=35514
View this thread: http://www.excelforum.com/showthread...hreadid=553818

  #3   Report Post  
Posted to microsoft.public.excel.misc
Ken Hudson
 
Posts: n/a
Default Macro help

Hi,
Try this code:

Dim Iloop as Integer
Sub PasteSLS()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
For Iloop = 1 to 500
If Not IsEmpty(Cells(Iloop,"C")) then
Cells(Iloop,"C") = "SLS"
End IF
Next Iloop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Your code has column C but your message talks about column G? If it is
column G, you'll need to code the code accordingly.

--
Ken Hudson


"TimmerSuds" wrote:


I have the following macro that inserts a new column and pastes SLS into
the new column. The way the macro is currently set is to paste it into
rows 2-33.

I need it to paste SLS into all rows in Column G that are not blank
(this can vary from 1 to 500 rows).

Here's the current macro. I'd appreciate any advice
Thanks!

Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
ActiveCell.FormulaR1C1 = "SLS"
Range("C1").Select
Selection.Copy
Range("C2:C33").Select
ActiveSheet.Paste


--
TimmerSuds
------------------------------------------------------------------------
TimmerSuds's Profile: http://www.excelforum.com/member.php...o&userid=35596
View this thread: http://www.excelforum.com/showthread...hreadid=553818


  #4   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett
 
Posts: n/a
Default Macro help

You code can be greatly simplified but you never told us how to determine
the last row.
Unless?, you really did mean the last row in col G instead of C. Then use
the 2nd.

Sub insertandfill()
Columns(3).Insert
Range("c1").Value = "SLS"
Range("c1").AutoFill Destination:=Range("c1:c33")
End Sub

Sub insertandfill()
lr=cells(rows.count,"g").end(xlup).row
Columns(3).Insert
Range("c1").Value = "SLS"
Range("c1").AutoFill Destination:=Range("c1:c" & lr)
End Sub

--
Don Guillett
SalesAid Software

"TimmerSuds" wrote
in message ...

I have the following macro that inserts a new column and pastes SLS into
the new column. The way the macro is currently set is to paste it into
rows 2-33.

I need it to paste SLS into all rows in Column G that are not blank
(this can vary from 1 to 500 rows).

Here's the current macro. I'd appreciate any advice
Thanks!

Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
ActiveCell.FormulaR1C1 = "SLS"
Range("C1").Select
Selection.Copy
Range("C2:C33").Select
ActiveSheet.Paste


--
TimmerSuds
------------------------------------------------------------------------
TimmerSuds's Profile:
http://www.excelforum.com/member.php...o&userid=35596
View this thread: http://www.excelforum.com/showthread...hreadid=553818



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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


All times are GMT +1. The time now is 10:31 PM.

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"