Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default visual basic macro help

i need a visual basic macro that will select all columns containing
comments and then insert an empty column to the right of each selected
column. any help? i found this code:

Dim iColumn As Long
On Error Resume Next
iColumn = Application.Match("Duration", Rows(1), 0)
On Error GoTo 0
If iColumn 0 Then
Columns(iColumn).Select
End If

for selecting columns that have "duration" in row 1, and this code:

Dim CommRange As Range
Dim MyCell As Range
Dim CurWks As Worksheet
Set CurWks = ActiveSheet
On Error Resume Next
Set CommRange = CurWks.Cells _
.SpecialCells(xlCellTypeComments)
On Error GoTo 0

for selecting cells with comments.


i'm not sure how to select columns with comments, though, and i'm
shooting in the dark for inserting colums to the right of the
selections... maybe add "Selection.EntireColumn.Select" after the
..specialcells() bit to change the cell selections to column selections?
either Selection.Entirecolumn.Insert or Selection.Insert
Shift:=xlToRight to insert the columns? i would guess that the second
option will insert to the right instead of to the left, but i'm just
guessing.

as you may have noticed, i've never used visual basic before, so i'm
probably overlooking something obvious.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default visual basic macro help

Here's what I have so far:

Sub comment_macro()

Dim CommentCell As Range

ActiveSheet.UsedRange.SpecialCells(xlCellTypeComme nts).Select

Set CommentCell = Selection

Selection.EntireColumn.Select
Selection.EntireColumn.Insert Shift:=xlToLeft

CommentCell.Select

For Each CommentCell In ActiveSheet.Cells
* CommentCell.Offset(0, 1).Value = CommentCell.Comment.Text
Next CommentCell

End Sub

i'm getting an "object variable not set" error on the asterisked line.
did i forget to define something, or should i have set CommentCell as
an Object instead of a Range?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default visual basic macro help

shadowsong,

I can't be sure, but I think your problem might be in your "For Each..." statement/loop. I would try something like this

For Each c in CommentCell
c.Offset(0, 1).Value = c.Comment.Text
Next c

If you have "Option Explicit" in General Declarations, you will need to declare "c" as a range variable. You can change "c" to
anything that is more meaningful to you.

I hope this helps,

Conan Kelly



wrote in message oups.com...
Here's what I have so far:

Sub comment_macro()

Dim CommentCell As Range

ActiveSheet.UsedRange.SpecialCells(xlCellTypeComme nts).Select

Set CommentCell = Selection

Selection.EntireColumn.Select
Selection.EntireColumn.Insert Shift:=xlToLeft

CommentCell.Select

For Each CommentCell In ActiveSheet.Cells
* CommentCell.Offset(0, 1).Value = CommentCell.Comment.Text
Next CommentCell

End Sub

i'm getting an "object variable not set" error on the asterisked line.
did i forget to define something, or should i have set CommentCell as
an Object instead of a Range?



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
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
Visual Basic Macro negzel Excel Discussion (Misc queries) 1 December 28th 04 10:53 PM
Visual Basic Macro For Solver Velero Excel Programming 3 February 19th 04 07:09 AM
Interpolation Visual Basic Macro!!!! L. Tucker[_2_] Excel Programming 3 September 12th 03 04:37 AM
visual basic macro in excel Patrick Molloy Excel Programming 0 July 23rd 03 07:49 AM


All times are GMT +1. The time now is 02:30 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"